Send smaller first batch (5 features) for faster first paint

Subsequent batches use the normal batch_size (default 50). This
reduces server-side time-to-first-property by ~10x since only 5
features need to be serialized before the first yield.
This commit is contained in:
Viktor Barzin 2026-02-22 13:24:01 +00:00
parent 9179456bf7
commit e99006e2f9
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 40 additions and 4 deletions

View file

@ -302,3 +302,16 @@ class TestStreamingEndpoint:
assert feature["properties"]["qm"] is None
assert feature["properties"]["qmprice"] is None
def test_first_batch_is_smaller(self, client, mock_repository):
"""Test that the first batch is smaller than subsequent batches for fast first paint."""
response = client.get("/api/listing_geojson/stream?listing_type=RENT&batch_size=50&limit=10")
lines = response.text.strip().split("\n")
messages = [json.loads(line) for line in lines]
batch_messages = [m for m in messages if m["type"] == "batch"]
assert len(batch_messages) >= 1
# First batch should contain FIRST_BATCH_SIZE (5) or fewer features
from api.app import FIRST_BATCH_SIZE
assert len(batch_messages[0]["features"]) <= FIRST_BATCH_SIZE