From 3495092effb34c1c442d399ccd3d632b44b9c37c Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Sat, 6 Jul 2024 18:15:21 +0530 Subject: [PATCH] add poolsize and availableconnections metrics back --- src/db/DittoDB.ts | 4 ++-- src/db/adapters/DittoPostgres.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/db/DittoDB.ts b/src/db/DittoDB.ts index 73cd1406..5607cf93 100644 --- a/src/db/DittoDB.ts +++ b/src/db/DittoDB.ts @@ -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; } diff --git a/src/db/adapters/DittoPostgres.ts b/src/db/adapters/DittoPostgres.ts index 7e085231..0f8547c1 100644 --- a/src/db/adapters/DittoPostgres.ts +++ b/src/db/adapters/DittoPostgres.ts @@ -8,13 +8,18 @@ import { KyselyLogger } from '@/db/KyselyLogger.ts'; export class DittoPostgres { static db: Kysely | undefined; + static postgres: postgres.Sql; // deno-lint-ignore require-await static async getInstance(): Promise> { + 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; + } }