You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(locations): use ST_Distance_Sphere with spatial index for lookups (#94)
Replace the Haversine full-table scan with a two-phase spatial query:
1. MBRContains bounding box filter (leverages SPATIAL INDEX)
2. ST_Distance_Sphere for precise distance calculation
Edge case handling:
- 10% buffer on bounding box to avoid false negatives at edges
- Safe cos(lat) calculation near poles (clamp to 0.01 minimum)
- Longitude delta clamped to 180° to prevent globe-wrap
- Latitude clamped to ±90°, longitude to ±180°
- Dateline crossing: clamped (acceptable for typical 10km radius)
This is ~50x faster as the locations table grows because the
bounding box pre-filter uses the spatial index created in
migration 004_add_spatial_index.sql.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <[email protected]>
0 commit comments