A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(api): advance the sort_id backfill by the picked batch
Hampus7a002fb4d3c7
diff --git a/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts b/fluxer_api/src/api/database/PostgresKvQueryExecutor.tsindex 1aee44e61..43170194f 100644--- a/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts+++ b/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts@@ -1111,7 +1111,7 @@ ON CONFLICT (table_name, row_key) DO UPDATE SET row_data = EXCLUDED.row_data, upasync function backfillPostgresKvSortIds(db: PostgresQueryable, table: string, tableName: string): Promise<void> {let after = '';for (;;) {- const result = await db.query<{filled: number; last: string | null}>(+ const result = await db.query<{picked: number; last: string | null}>(`WITH batch AS (SELECT row_key FROM ${table}WHERE table_name = $1 AND row_key COLLATE "C" > $2 AND sort_id IS NULL@@ -1123,11 +1123,11 @@ async function backfillPostgresKvSortIds(db: PostgresQueryable, table: string, tFROM batchWHERE kv.table_name = $1 AND kv.row_key = batch.row_key)-SELECT count(*)::int AS filled, max(row_key COLLATE "C") AS last FROM filled`,+SELECT count(*)::int AS picked, max(row_key COLLATE "C") AS last FROM batch`,[tableName, after, POSTGRES_KV_SORT_ID_BACKFILL_BATCH],);const row = result.rows[0];- if (!row?.last || row.filled < POSTGRES_KV_SORT_ID_BACKFILL_BATCH) return;+ if (!row?.last || row.picked < POSTGRES_KV_SORT_ID_BACKFILL_BATCH) return;after = row.last;}}