switch to deno.land/postgresjs for free 4x speed increase

This commit is contained in:
Siddharth Singh 2024-07-01 21:42:50 +05:30
parent ae140933f5
commit 98aaab8e51
No known key found for this signature in database
4 changed files with 10 additions and 2 deletions

View file

@ -50,8 +50,8 @@
"iso-639-1": "npm:iso-639-1@2.1.15", "iso-639-1": "npm:iso-639-1@2.1.15",
"isomorphic-dompurify": "npm:isomorphic-dompurify@^2.11.0", "isomorphic-dompurify": "npm:isomorphic-dompurify@^2.11.0",
"kysely": "npm:kysely@^0.27.3", "kysely": "npm:kysely@^0.27.3",
"postgres": "https://deno.land/x/postgresjs@v3.4.3/mod.js",
"kysely-postgres-js": "npm:kysely-postgres-js@2.0.0", "kysely-postgres-js": "npm:kysely-postgres-js@2.0.0",
"postgres": "npm:postgres@3.4.4",
"light-bolt11-decoder": "npm:light-bolt11-decoder", "light-bolt11-decoder": "npm:light-bolt11-decoder",
"linkify-plugin-hashtag": "npm:linkify-plugin-hashtag@^4.1.1", "linkify-plugin-hashtag": "npm:linkify-plugin-hashtag@^4.1.1",
"linkify-string": "npm:linkify-string@^4.1.1", "linkify-string": "npm:linkify-string@^4.1.1",

View file

@ -1,4 +1,10 @@
import { DittoDB } from '@/db/DittoDB.ts'; import { DittoDB } from '@/db/DittoDB.ts';
import { delay } from '@/test.ts';
if (Deno.env.get('CI') && Deno.env.get('DATABASE_URL')?.startsWith('postgres')) {
console.info('Waiting 15 seconds for postgres to start...');
await delay(15000);
}
const kysely = await DittoDB.getInstance(); const kysely = await DittoDB.getInstance();
await kysely.destroy(); await kysely.destroy();

View file

@ -14,7 +14,7 @@ export class DittoPostgres {
if (!this.db) { if (!this.db) {
this.db = new Kysely({ this.db = new Kysely({
dialect: new PostgresJSDialect({ dialect: new PostgresJSDialect({
postgres: postgres(Conf.databaseUrl) postgres: postgres(Conf.databaseUrl) as any
}), }),
log: KyselyLogger log: KyselyLogger
}); });

View file

@ -62,3 +62,5 @@ export async function getTestDB() {
[Symbol.asyncDispose]: () => kysely.destroy(), [Symbol.asyncDispose]: () => kysely.destroy(),
}; };
} }
export const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));