Conversation
… sites
The `GET /api/v1/dive-sites/{id}/nearby` endpoint previously calculated
distances using the Haversine formula on standard float columns, forcing
a full table scan and dynamic calculation for every query.
This commit resolves the performance bottleneck by:
- Adding a `location` column of type `POINT SRID 4326` to `dive_sites`
- Applying a `SPATIAL INDEX` to the `location` column
- Adding SQLAlchemy event listeners to sync `latitude` and `longitude`
into the new `location` POINT on insert/update
- Refactoring the `/nearby` endpoint to execute a highly optimized
raw MySQL `ST_Distance_Sphere` query
- Generating Alembic migration 0073 to backfill existing data
- Adding `@pytest.mark.spatial` to test coverage
The frontend API contract and UI remain completely unaffected,
but map and detail views rendering nearby sites will now
scale efficiently regardless of database size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
GET /api/v1/dive-sites/{id}/nearbyendpoint previously calculated distances using the Haversine formula on standard float columns, forcing a full table scan and dynamic calculation for every query.This commit resolves the performance bottleneck by:
locationcolumn of typePOINT SRID 4326todive_sitesSPATIAL INDEXto thelocationcolumnlatitudeandlongitudeinto the newlocationPOINT on insert/update/nearbyendpoint to execute a highly optimized raw MySQLST_Distance_Spherequery@pytest.mark.spatialto test coverageThe frontend API contract and UI remain completely unaffected, but map and detail views rendering nearby sites will now scale efficiently regardless of database size.