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:
parent
9179456bf7
commit
e99006e2f9
2 changed files with 40 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue