datasette/perf/request-response/patches/response-serialization-4-head-skips-csv-generation.diff
Claude d1dbb40362
Add request/response profiling harness and proposed optimisation patches
Tools for profiling Datasette's request/response cycle in-process with
Python 3.15's profiling.sampling, plus the patches proposed by the study
(one per optimisation, and ALL-combined.diff). The patches are not
applied to the code. A report with measurements follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F8mEgRS8swZfYqwqrVMeo5
2026-10-13 00:12:35 +00:00

14 lines
550 B
Diff

diff --git a/datasette/views/base.py b/datasette/views/base.py
index 7262edb..f2d63aa 100644
--- a/datasette/views/base.py
+++ b/datasette/views/base.py
@@ -335,4 +335,9 @@ async def stream_csv(datasette, fetch_data, request, database):
)
headers["content-disposition"] = disposition
+ if request.method == "HEAD":
+ # A HEAD response has no body, so don't generate (and paginate) the CSV
+ async def stream_fn(r):
+ pass
+
return AsgiStream(stream_fn, headers=headers, content_type=content_type)