Skip to content

Commit ebea118

Browse files
fix: Use jwt_private.current_database_id() instead of querying metaschema_public.database
The server middleware already sets jwt.claims.database_id in pgSettings, so jwt_private.current_database_id() is a cheap function call vs the previous approach of querying metaschema_public.database on every request.
1 parent b677569 commit ebea118

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • graphile/graphile-presigned-url-plugin/src

graphile/graphile-presigned-url-plugin/src/plugin.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ function buildS3Key(contentHash: string): string {
5454
}
5555

5656
/**
57-
* Resolve the database_id from the pgClient's current database.
58-
* This queries metaschema to find the database row for the current connection.
57+
* Resolve the database_id from the JWT context.
58+
* The server middleware sets jwt.claims.database_id, which is accessible
59+
* via jwt_private.current_database_id() — a simple function call, no
60+
* metaschema query needed.
5961
*/
6062
async function resolveDatabaseId(pgClient: any): Promise<string | null> {
6163
const result = await pgClient.query(
62-
`SELECT id FROM metaschema_public.database WHERE db_name = current_database() LIMIT 1`,
64+
`SELECT jwt_private.current_database_id() AS id`,
6365
);
64-
if (result.rows.length === 0) return null;
65-
return result.rows[0].id;
66+
return result.rows[0]?.id ?? null;
6667
}
6768

6869
// --- Plugin factory ---

0 commit comments

Comments
 (0)