Skip to content

Feat/read replica for geocoding#305

Merged
joaquimds merged 2 commits intomainfrom
feat/read-replica-for-geocoding
Feb 5, 2026
Merged

Feat/read replica for geocoding#305
joaquimds merged 2 commits intomainfrom
feat/read-replica-for-geocoding

Conversation

@joaquimds
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 findAreasByPoint function to use the read replica for expensive spatial queries
  • Created database migration to add a composite GIST index on area_set_id and geography columns 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.

Comment on lines +13 to +14
await sql`DROP EXTENSION IF EXISTS btree_gist`.execute(db);
}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
await sql`DROP EXTENSION IF EXISTS btree_gist`.execute(db);
}
}

Copilot uses AI. Check for mistakes.
areaDataSourceId: electionResultsDataSource.id,
areaSetGroupCode: AreaSetGroupCode.WMC24,
calculationType: null,
calculationType: DEFAULT_CALCULATION_TYPE,
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
mapStyleName: MapStyleName.Light,
reverseColorScheme: false,
showBoundaryOutline: true,
showChoropleth: true,
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@joaquimds joaquimds merged commit cb058c7 into main Feb 5, 2026
8 checks passed
@joaquimds joaquimds deleted the feat/read-replica-for-geocoding branch February 5, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant