mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-23 23:34:26 +01:00
add poolsize and availableconnections metrics back
This commit is contained in:
@@ -39,14 +39,14 @@ export class DittoDB {
|
||||
|
||||
static get poolSize(): number {
|
||||
if (Conf.db.dialect === 'postgres') {
|
||||
return DittoPostgres.getPool().size;
|
||||
return DittoPostgres.poolSize;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static get availableConnections(): number {
|
||||
if (Conf.db.dialect === 'postgres') {
|
||||
return DittoPostgres.getPool().available;
|
||||
return DittoPostgres.availableConnections;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -8,13 +8,18 @@ import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
||||
|
||||
export class DittoPostgres {
|
||||
static db: Kysely<DittoTables> | undefined;
|
||||
static postgres: postgres.Sql;
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
static async getInstance(): Promise<Kysely<DittoTables>> {
|
||||
if (!this.postgres) {
|
||||
this.postgres = postgres(Conf.databaseUrl, { max: Conf.pg.poolSize }) as any;
|
||||
}
|
||||
|
||||
if (!this.db) {
|
||||
this.db = new Kysely({
|
||||
dialect: new PostgresJSDialect({
|
||||
postgres: postgres(Conf.databaseUrl) as any,
|
||||
postgres: this.postgres,
|
||||
}),
|
||||
log: KyselyLogger,
|
||||
});
|
||||
@@ -22,4 +27,14 @@ export class DittoPostgres {
|
||||
|
||||
return this.db;
|
||||
}
|
||||
|
||||
static get poolSize() {
|
||||
return Conf.pg.poolSize;
|
||||
}
|
||||
|
||||
static get availableConnections(): number {
|
||||
// blocked by https://github.com/porsager/postgres/pull/911
|
||||
// return this.postgres.availableConnections;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user