diff --git a/backend/src/board-store.ts b/backend/src/board-store.ts index b460dafe8..3c82f1756 100644 --- a/backend/src/board-store.ts +++ b/backend/src/board-store.ts @@ -29,7 +29,7 @@ with allow_lists as ( from board_access a where a.board_id = b.id ) as allow_list - from board b + from board b for update ) select id, jsonb_set (content - 'accessPolicy', '{accessPolicy}', cast(case when allow_list is null then 'null' else (json_build_object('allowList', allow_list, 'publicRead', public_read, 'publicWrite', public_write)) end as jsonb)) as content diff --git a/backend/src/compact-history.ts b/backend/src/compact-history.ts index 151e07258..6546550e1 100644 --- a/backend/src/compact-history.ts +++ b/backend/src/compact-history.ts @@ -15,10 +15,13 @@ import { verifyContinuityFromMetas, } from "./board-store" import { inTransaction } from "./db" +import { sleep } from "../../common/src/sleep" export async function quickCompactBoardHistory(id: Id) { let fallback = false const result = inTransaction(async (client) => { + // Lock the board to prevent loading the board while compacting + await client.query("select 1 from board where id=$1 for update", [id]) const bundleMetas = await getBoardHistoryBundleMetas(client, id) if (bundleMetas.length === 0) return const consistent = verifyContinuityFromMetas(id, 0, bundleMetas)