A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(api): run the kv sort_id migration in the background
Hampus1877825657da
diff --git a/fluxer_api/pkgs/postgres/src/Client.ts b/fluxer_api/pkgs/postgres/src/Client.tsindex 5c7eac55e..ed7d3bcd2 100644--- a/fluxer_api/pkgs/postgres/src/Client.ts+++ b/fluxer_api/pkgs/postgres/src/Client.ts@@ -120,6 +120,7 @@ class PostgresClient implements IPostgresClient {private activeOperations = 0;private resolveOperationsDrained: (() => void) | null = null;private readonly acquiredConnections = new WeakMap<PoolClient, AcquiredPostgresConnection>();+ private readonly sessions = new Set<PoolClient>();constructor(config: PostgresConfig,@@ -214,6 +215,7 @@ class PostgresClient implements IPostgresClient {private async closePool(): Promise<void> {await this.connection;+ for (const client of this.sessions) void client.end().catch(() => {});if (this.activeOperations > 0) {await new Promise<void>((resolve) => {this.resolveOperationsDrained = resolve;@@ -276,11 +278,13 @@ class PostgresClient implements IPostgresClient {async session<T>(fn: (client: PostgresQueryable) => Promise<T>): Promise<T> {return this.withPool(async (pool) => {const client = await pool.connect();+ this.sessions.add(client);try {const acquired = this.getAcquiredConnection(client);if (acquired.error) throw acquired.error;return await runConnectionCallback(client, acquired, this.config.preparedStatements !== false, fn);} finally {+ this.sessions.delete(client);client.release(true);}});diff --git a/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts b/fluxer_api/src/api/database/PostgresKvQueryExecutor.tsindex e550af263..5cace34be 100644--- a/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts+++ b/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts@@ -1047,6 +1047,11 @@ export async function ensurePostgresKvSchema(client: IPostgresClient): Promise<v}}await enableStatementStats(client);+ if (await postgresKvIndexesPending(client)) {+ void client+ .session((db) => migratePostgresKvIndexes(db, client.kvTable()))+ .catch((error: unknown) => logError({error, table: client.kvTable()}, 'Postgres KV sort_id migration failed'));+ }}async function enableStatementStats(client: IPostgresClient): Promise<void> {