-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add timeout decorator to connection and table schema controllers; configure knex connection pool #1783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import knex, { Knex } from 'knex'; | ||
| import getPort from 'get-port'; | ||
| import knex, { Knex } from 'knex'; | ||
| import { LRUStorage } from '../caching/lru-storage.js'; | ||
| import { ConnectionParams } from '../data-access-layer/shared/data-structures/connections-params.ds.js'; | ||
| import { getTunnel } from '../helpers/get-ssh-tunnel.js'; | ||
| import { LRUStorage } from '../caching/lru-storage.js'; | ||
| export class KnexManager { | ||
| static knexStorage() { | ||
| const knexMap = new Map<ConnectionParams['type'], (connection: ConnectionParams) => Promise<Knex<any, any[]>>>(); | ||
|
|
@@ -126,6 +126,7 @@ export class KnexManager { | |
|
|
||
| private static getPostgresKnex(connection: ConnectionParams): Knex<any, any[]> { | ||
| const { host, username, password, database, port, type, cert, ssl } = connection; | ||
| const pool = { min: 0, max: 3 }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Find PostgreSQL connection usage patterns to assess concurrency needs
# Find all controller methods that might use database connections
echo "=== Endpoints that could use PostgreSQL connections ==="
rg -n -A 2 '@(Get|Post|Put|Delete)\(' backend/src/entities/connection/connection.controller.ts backend/src/entities/table-schema/table-schema.controller.ts | head -50
# Check if there are use cases that might hold connections for extended periods
echo -e "\n=== Use cases that might perform long-running database operations ==="
rg -n 'getConnectionDiagram|generate.*schema|approve.*schema|rollback.*schema' backend/src/entities/ -A 3 | head -30Repository: rocket-admin/rocketadmin Length of output: 9756 🏁 Script executed: # Read the knex-manager.ts file to see full context
cat -n shared-code/src/knex-manager/knex-manager.ts | head -150Repository: rocket-admin/rocketadmin Length of output: 5688 🏁 Script executed: # Search for 90-second timeout references in the PR
rg '90|9000|timeout' backend/src/entities/table-schema/ --type ts -A 2 -B 2Repository: rocket-admin/rocketadmin Length of output: 2489 🏁 Script executed: # Check if there are other pool configurations in the codebase
rg 'pool.*max|max.*pool|connectionLimit' shared-code/ backend/ --type ts -B 2 -A 2Repository: rocket-admin/rocketadmin Length of output: 561 🏁 Script executed: # Look for any concurrency or load testing documentation
find . -type f \( -name "*.md" -o -name "*.txt" \) -exec grep -l "concurrent\|concurrency\|load\|pool\|connection" {} \; | head -20Repository: rocket-admin/rocketadmin Length of output: 397 🏁 Script executed: # Look for deployment or load testing documentation
find . -type f \( -name "*.md" -o -name "*.yaml" -o -name "*.yml" -o -name "*.json" \) | xargs grep -l "deployment\|scale\|concurrent\|load\|pool" 2>/dev/null | head -20Repository: rocket-admin/rocketadmin Length of output: 448 🏁 Script executed: # Check if there are environment-based pool configurations
rg 'pool|max.*connection|CONNECTION' backend/src/ shared-code/src/ --type ts --type json -B 2 -A 2 | grep -A 3 -B 3 'env\|ENV'Repository: rocket-admin/rocketadmin Length of output: 1046 🏁 Script executed: # Check the connection cache implementation to understand scope
cat -n shared-code/src/caching/lru-storage.ts | head -100Repository: rocket-admin/rocketadmin Length of output: 5631 Verify that The Consider:
🤖 Prompt for AI Agents |
||
| if (process.env.NODE_ENV === 'test') { | ||
| const newKnex = knex({ | ||
| client: type, | ||
|
|
@@ -137,6 +138,7 @@ export class KnexManager { | |
| port: port, | ||
| application_name: 'rocketadmin', | ||
| }, | ||
| pool, | ||
| }); | ||
| return newKnex; | ||
| } | ||
|
|
@@ -155,6 +157,7 @@ export class KnexManager { | |
| rejectUnauthorized: false, | ||
| }, | ||
| }, | ||
| pool, | ||
| }); | ||
| return newKnex; | ||
| } | ||
|
|
@@ -169,6 +172,7 @@ export class KnexManager { | |
| application_name: 'rocketadmin', | ||
| ssl: ssl ? { ca: cert ?? undefined, rejectUnauthorized: !cert } : false, | ||
| }, | ||
| pool, | ||
| }); | ||
| return newKnex; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift
Class-level timeout may be too broad for read and reject operations.
The 90-second timeout applies to all routes in this controller except
generate(which has its own override). Several operations are unlikely to need 90 seconds:get(line 168),list(line 152),getBatch(line 228)reject(line 127),rejectBatch(line 202)Operations that execute SQL migrations (
approve,rollback,approveBatch,rollbackBatch) are the ones that justify extended timeouts. Consider applying@Timeout(90000)selectively at the method level for those endpoints instead of at the class level.⏱️ Suggested approach: Apply timeouts selectively
Remove the class-level
@Timeout(90000)and apply it only to SQL-executing operations:`@UseInterceptors`(SentryInterceptor) -@Timeout(90000) `@Controller`() `@ApiBearerAuth`() `@ApiTags`('Table Schema Changes')Then add method-level decorators:
`@ApiOperation`({ summary: 'Approve and apply a pending schema change.' }) `@ApiParam`({ name: 'changeId', type: String }) `@ApiBody`({ type: ApproveSchemaChangeDto, required: false }) `@ApiResponse`({ status: 200, type: SchemaChangeResponseDto }) `@UseGuards`(SchemaChangeOwnershipGuard) +@Timeout(90000) `@Post`('/table-schema/change/:changeId/approve')Apply the same pattern to
rollback,approveBatch, androllbackBatch.🤖 Prompt for AI Agents