Skip to content

Commit d2d09a8

Browse files
authored
Merge pull request #1783 from rocket-admin/backend_table_schema_timeouts
feat: add timeout decorator to connection and table schema controllers; configure knex connection pool
2 parents a891341 + e15f40f commit d2d09a8

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

backend/src/entities/connection/connection.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ export class ConnectionController {
737737
type: ConnectionDiagramResponseDTO,
738738
})
739739
@UseGuards(ConnectionDiagramGuard)
740+
@Timeout(90000)
740741
@Get('/connection/diagram/:connectionId')
741742
async getConnectionDiagram(
742743
@SlugUuid('connectionId') connectionId: string,

backend/src/entities/table-schema/table-schema.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
} from './use-cases/table-schema-use-cases.interface.js';
4242

4343
@UseInterceptors(SentryInterceptor)
44+
@Timeout(90000)
4445
@Controller()
4546
@ApiBearerAuth()
4647
@ApiTags('Table Schema Changes')

shared-code/src/knex-manager/knex-manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import knex, { Knex } from 'knex';
21
import getPort from 'get-port';
2+
import knex, { Knex } from 'knex';
3+
import { LRUStorage } from '../caching/lru-storage.js';
34
import { ConnectionParams } from '../data-access-layer/shared/data-structures/connections-params.ds.js';
45
import { getTunnel } from '../helpers/get-ssh-tunnel.js';
5-
import { LRUStorage } from '../caching/lru-storage.js';
66
export class KnexManager {
77
static knexStorage() {
88
const knexMap = new Map<ConnectionParams['type'], (connection: ConnectionParams) => Promise<Knex<any, any[]>>>();
@@ -126,6 +126,7 @@ export class KnexManager {
126126

127127
private static getPostgresKnex(connection: ConnectionParams): Knex<any, any[]> {
128128
const { host, username, password, database, port, type, cert, ssl } = connection;
129+
const pool = { min: 0, max: 3 };
129130
if (process.env.NODE_ENV === 'test') {
130131
const newKnex = knex({
131132
client: type,
@@ -137,6 +138,7 @@ export class KnexManager {
137138
port: port,
138139
application_name: 'rocketadmin',
139140
},
141+
pool,
140142
});
141143
return newKnex;
142144
}
@@ -155,6 +157,7 @@ export class KnexManager {
155157
rejectUnauthorized: false,
156158
},
157159
},
160+
pool,
158161
});
159162
return newKnex;
160163
}
@@ -169,6 +172,7 @@ export class KnexManager {
169172
application_name: 'rocketadmin',
170173
ssl: ssl ? { ca: cert ?? undefined, rejectUnauthorized: !cert } : false,
171174
},
175+
pool,
172176
});
173177
return newKnex;
174178
}

0 commit comments

Comments
 (0)