Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds read replica support for database queries, specifically optimizing expensive geocoding operations. The implementation creates a separate database connection pool for read replicas with graceful fallback to the primary database.
Changes:
- Added read replica database pool and Kysely instance (
dbRead) with automatic fallback to primary database - Modified
findAreasByPointfunction to use the read replica for expensive spatial queries - Created database migration to add a composite GIST index on
area_set_idandgeographycolumns for improved query performance - Refactored database plugins into a shared array to avoid duplication
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/server/services/database/index.ts | Sets up read replica pool, dialect, and Kysely instance with fallback to primary database; refactors plugins into shared array |
| src/server/repositories/Area.ts | Updates findAreasByPoint to use dbRead for expensive geocoding queries |
| src/server/commands/ensureOrganisationMap.ts | Adds DEFAULT_CALCULATION_TYPE constant and showChoropleth field to map view configuration (unrelated to read replica feature) |
| migrations/1770221306067_area_set_id_geography_index.ts | Creates composite GIST index on area table to optimize spatial queries used in geocoding |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await sql`DROP EXTENSION IF EXISTS btree_gist`.execute(db); | ||
| } |
There was a problem hiding this comment.
Dropping the btree_gist extension in the down migration is potentially unsafe. If other GIST indexes or database objects depend on this extension, the DROP EXTENSION command will fail. PostgreSQL extensions are shared across the database, not tied to individual indexes. Consider removing this line from the down migration, as the extension may be needed by other parts of the database or future migrations. The index removal on line 12 is sufficient for the down migration.
| await sql`DROP EXTENSION IF EXISTS btree_gist`.execute(db); | |
| } | |
| } |
| areaDataSourceId: electionResultsDataSource.id, | ||
| areaSetGroupCode: AreaSetGroupCode.WMC24, | ||
| calculationType: null, | ||
| calculationType: DEFAULT_CALCULATION_TYPE, |
There was a problem hiding this comment.
This change from null to DEFAULT_CALCULATION_TYPE appears unrelated to the read replica feature described in the PR title. While this may be a valid improvement, including unrelated changes in a feature PR can make code review more difficult and complicates the git history. Consider moving this to a separate PR or documenting it in the PR description.
| mapStyleName: MapStyleName.Light, | ||
| reverseColorScheme: false, | ||
| showBoundaryOutline: true, | ||
| showChoropleth: true, |
There was a problem hiding this comment.
The addition of showChoropleth appears unrelated to the read replica feature described in the PR title. While this may be a valid improvement, including unrelated changes in a feature PR can make code review more difficult and complicates the git history. Consider moving this to a separate PR or documenting it in the PR description.
No description provided.