Skip to content

Commit d5d2c8e

Browse files
fix(sync-server): forward exact ops to local subscribers
1 parent 03e8f1d commit d5d2c8e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

  • packages/sync/server/postgres-node/src

packages/sync/server/postgres-node/src/server.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type DocContext = {
9494

9595
type PostgresNodeDocStore = {
9696
provider: WebSocketSyncServerDocProvider<Operation>;
97-
notifyDocUpdate: (docId: string) => void;
97+
notifyDocUpdate: (docId: string, ops?: readonly Operation[]) => void;
9898
closeAll: () => Promise<void>;
9999
};
100100

@@ -404,10 +404,10 @@ export function createPostgresNodeDocStore(opts: PostgresNodeDocStoreOptions): P
404404
let closing = false;
405405
let closeAllPromise: Promise<void> | undefined;
406406

407-
const notifyDocUpdate = (docId: string): void => {
407+
const notifyDocUpdate = (docId: string, ops?: readonly Operation[]): void => {
408408
const ctx = docs.get(docId);
409409
if (!ctx) return;
410-
for (const peer of ctx.peers) void peer.notifyLocalUpdate();
410+
for (const peer of ctx.peers) void peer.notifyLocalUpdate(ops);
411411
};
412412

413413
const closeBackend = async (backend: SyncBackend<Operation>): Promise<void> => {
@@ -458,7 +458,9 @@ export function createPostgresNodeDocStore(opts: PostgresNodeDocStoreOptions): P
458458
} catch {
459459
// ignore notify failures; local update path still proceeds
460460
}
461-
notifyDocUpdate(ctx.docId);
461+
// Local peers in this Node process can take the exact applied ops fast path.
462+
// Cross-process listeners still fall back to doc-level pg_notify invalidation.
463+
notifyDocUpdate(ctx.docId, ops);
462464
};
463465
return {
464466
...backend,

0 commit comments

Comments
 (0)