Skip to content

Commit 30ec754

Browse files
committed
refactor(dashboard-agent-db): move the watch queries into their own module
Pure move: the watch, wake and batch-chain queries leave queries.ts for watch-queries.ts, re-exported so every import path still resolves.
1 parent d6debe8 commit 30ec754

3 files changed

Lines changed: 965 additions & 944 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { sql } from "drizzle-orm";
2+
import type { DashboardAgentDb } from "./client.js";
3+
4+
// Shared by `queries.ts` and `watch-queries.ts`. Not part of the package's surface.
5+
6+
export type DashboardAgentDbOrTx =
7+
| DashboardAgentDb
8+
| Parameters<Parameters<DashboardAgentDb["transaction"]>[0]>[0];
9+
10+
/** Advisory-lock namespace (ASCII `watc`), so keys can't collide with another lock. */
11+
const WATCH_CHAT_LOCK_NAMESPACE = 0x77617463;
12+
13+
/** Serializes creating a watch against deleting the chat under it. Transaction-scoped. */
14+
export function lockChatForWatches(tx: DashboardAgentDbOrTx, chatId: string) {
15+
return tx.execute(
16+
sql`select pg_advisory_xact_lock(${WATCH_CHAT_LOCK_NAMESPACE}, hashtext(${chatId}))`
17+
);
18+
}

0 commit comments

Comments
 (0)