feat: write routes live during scan instead of bulk-insert at completion

Routes and individual flights are now written to the database as each
query result arrives, rather than after all queries finish. The frontend
already polls /scans/:id/routes while status=running, so routes appear
progressively with no frontend changes needed.

Changes:
- database/schema.sql: UNIQUE INDEX uq_routes_scan_dest(scan_id, destination)
- database/init_db.py: _migrate_add_routes_unique_index() migration
- scan_processor.py: _write_route_incremental() helper; progress_callback
  now writes routes/flights immediately; Phase 2 bulk-write replaced with
  a lightweight totals query
- searcher_v3.py: pass flights= kwarg to progress_callback on cache_hit
  and api_success paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 20:53:04 +01:00
parent 4926e89e46
commit ce1cf667d2
5 changed files with 592 additions and 93 deletions

View File

@@ -118,7 +118,7 @@ async def search_direct_flights(
)
if cached is not None:
if progress_callback:
progress_callback(origin, destination, date, "cache_hit", len(cached))
progress_callback(origin, destination, date, "cache_hit", len(cached), flights=cached)
return cached
# Add random delay to avoid rate limiting
@@ -140,7 +140,7 @@ async def search_direct_flights(
# Report progress
if progress_callback:
progress_callback(origin, destination, date, "api_success", len(result))
progress_callback(origin, destination, date, "api_success", len(result), flights=result)
return result