fix: read-after-write issues (#215)
* fix: read-after-write issues * fix: coderabbit comments * fix: clear cache on invite * fix: use primary after a read
This commit is contained in:
committed by
GitHub
parent
abacf66155
commit
f454449365
12
packages/db/src/session-context.ts
Normal file
12
packages/db/src/session-context.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
|
||||
type Ctx = { sessionId: string | null };
|
||||
|
||||
export const als = new AsyncLocalStorage<Ctx>();
|
||||
|
||||
export const runWithAlsSession = <T>(
|
||||
sid: string | null | undefined,
|
||||
fn: () => Promise<T>,
|
||||
) => als.run({ sessionId: sid || null }, fn);
|
||||
|
||||
export const getAlsSessionId = () => als.getStore()?.sessionId ?? null;
|
||||
Reference in New Issue
Block a user