add poolsize and availableconnections metrics back

This commit is contained in:
Siddharth Singh 2024-07-06 18:15:21 +05:30
parent a804608afb
commit 3495092eff
No known key found for this signature in database
2 changed files with 18 additions and 3 deletions

View file

@ -39,14 +39,14 @@ export class DittoDB {
static get poolSize(): number { static get poolSize(): number {
if (Conf.db.dialect === 'postgres') { if (Conf.db.dialect === 'postgres') {
return DittoPostgres.getPool().size; return DittoPostgres.poolSize;
} }
return 1; return 1;
} }
static get availableConnections(): number { static get availableConnections(): number {
if (Conf.db.dialect === 'postgres') { if (Conf.db.dialect === 'postgres') {
return DittoPostgres.getPool().available; return DittoPostgres.availableConnections;
} }
return 1; return 1;
} }

View file

@ -8,13 +8,18 @@ import { KyselyLogger } from '@/db/KyselyLogger.ts';
export class DittoPostgres { export class DittoPostgres {
static db: Kysely<DittoTables> | undefined; static db: Kysely<DittoTables> | undefined;
static postgres: postgres.Sql;
// deno-lint-ignore require-await // deno-lint-ignore require-await
static async getInstance(): Promise<Kysely<DittoTables>> { static async getInstance(): Promise<Kysely<DittoTables>> {
if (!this.postgres) {
this.postgres = postgres(Conf.databaseUrl, { max: Conf.pg.poolSize }) as any;
}
if (!this.db) { if (!this.db) {
this.db = new Kysely({ this.db = new Kysely({
dialect: new PostgresJSDialect({ dialect: new PostgresJSDialect({
postgres: postgres(Conf.databaseUrl) as any, postgres: this.postgres,
}), }),
log: KyselyLogger, log: KyselyLogger,
}); });
@ -22,4 +27,14 @@ export class DittoPostgres {
return this.db; 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;
}
} }