mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## Context Part of dashboard scalability project Opting to use the connection string of the project's read replica (if available) for read queries on the database. Trialing with the Table Editor as a first pass - changes involved will opt to use replica connection string for `useTableRowsQuery`, `useTableRowsCountQuery`, and `useForeignKeyConstraintsQuery` There's definitely optimizations to be done for deciding which replica to use - but am starting off with a rather naive logic to prioritize replicas in the same region as the project. ## Changes involved - We're no longer passing `connectionString` as a param into the affected hooks, the `connectionString` is derived from within those hooks instead - Change is feature flagged, so things should be status quo if flag is off (use primary database's connection string) - Added `useConnectionStringForReadOps` hook which returns the replica's connection string if (Otherwise defaults to primary database connection string) - Feature flag is on - Project has a replica available ## To test - [ ] Verify that the table editor works as expected for a project that has read replicas (There shouldn't be any change really) - [ ] Also just double check that updating cells in the table editor works as well (There's no change there, we're using the primary DB's connection string for mutation ops) - [ ] ^ Same thing for a project that doesn't have read replicas - [ ] ^ Same thing for local / self-host
52 lines
2.9 KiB
TypeScript
52 lines
2.9 KiB
TypeScript
export const databaseKeys = {
|
|
schemas: (projectRef: string | undefined) => ['projects', projectRef, 'schemas'] as const,
|
|
keywords: (projectRef: string | undefined) => ['projects', projectRef, 'keywords'] as const,
|
|
migrations: (projectRef: string | undefined) => ['projects', projectRef, 'migrations'] as const,
|
|
tableColumns: (
|
|
projectRef: string | undefined,
|
|
schema: string | undefined,
|
|
table: string | undefined
|
|
) => ['projects', projectRef, 'table-columns', schema, table] as const,
|
|
databaseFunctions: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database-functions'] as const,
|
|
entityDefinition: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'entity-definition', id] as const,
|
|
entityDefinitions: (projectRef: string | undefined, schemas: string[]) =>
|
|
['projects', projectRef, 'entity-definitions', schemas] as const,
|
|
tableDefinition: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'table-definition', id] as const,
|
|
viewDefinition: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'view-definition', id] as const,
|
|
backups: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database', 'backups'] as const,
|
|
poolingConfiguration: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database', 'pooling-configuration'] as const,
|
|
indexesFromQuery: (projectRef: string | undefined, query: string) =>
|
|
['projects', projectRef, 'indexes', { query }] as const,
|
|
indexAdvisorFromQuery: (projectRef: string | undefined, query: string) =>
|
|
['projects', projectRef, 'index-advisor', { query }] as const,
|
|
tableConstraints: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'table-constraints', id] as const,
|
|
foreignKeyConstraints: (projectRef: string | undefined, schema?: string, options = {}) =>
|
|
['projects', projectRef, 'foreign-key-constraints', schema, options] as const,
|
|
databaseSize: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database-size'] as const,
|
|
maxConnections: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'max-connections'] as const,
|
|
pgbouncerStatus: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'pgbouncer', 'status'] as const,
|
|
pgbouncerConfig: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'pgbouncer', 'config'] as const,
|
|
checkPrimaryKeysExists: (
|
|
projectRef: string | undefined,
|
|
tables: { name: string; schema: string }[]
|
|
) => ['projects', projectRef, 'check-primary-keys', tables] as const,
|
|
tableIndexAdvisor: (
|
|
projectRef: string | undefined,
|
|
schema: string | undefined,
|
|
table: string | undefined
|
|
) => ['projects', projectRef, 'table-index-advisor', schema, table] as const,
|
|
supamonitorEnabled: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'supamonitor-enabled'] as const,
|
|
}
|