Skip to content

Commit dbb6585

Browse files
t3dotggclaude
andcommitted
perf(server): build the thread list snapshot without decoding it twice
getShellSnapshot and getArchivedShellSnapshot built the snapshot from rows that SqlSchema had already decoded, then ran a second full OrchestrationShellSnapshot decode over the result. With thousands of threads that is about 45 ms and one full object copy per build, and about 9 callers build it, several times a minute. Return the built snapshot directly and check it with `satisfies`. The HTTP and RPC layers still encode it against OrchestrationShellSnapshot (which trims and validates), the same way the per-item shells from getThreadShellById already work. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 6530de0 commit dbb6585

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

‎apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
OrchestrationProposedPlanId,
1313
OrchestrationReadModel,
1414
OrchestrationThreadSearchSource,
15-
OrchestrationShellSnapshot,
15+
type OrchestrationShellSnapshot,
1616
OrchestrationThread,
1717
OrchestrationThreadDetailSnapshot,
1818
ProjectScript,
@@ -82,7 +82,6 @@ import {
8282
} from "../Services/ProjectionSnapshotQuery.ts";
8383

8484
const decodeReadModel = Schema.decodeUnknownEffect(OrchestrationReadModel);
85-
const decodeShellSnapshot = Schema.decodeUnknownEffect(OrchestrationShellSnapshot);
8685
const decodeThread = Schema.decodeUnknownEffect(OrchestrationThread);
8786
const decodeImportedTranscriptsPayload = Schema.decodeUnknownOption(
8887
Schema.fromJsonString(
@@ -2746,7 +2745,10 @@ pending_approval_requests AS (
27462745
);
27472746
const pullRequestsByThread = groupPullRequestRowsByThread(pullRequestRows);
27482747

2749-
const snapshot = {
2748+
// Built from schema-decoded rows, so no second decode here. The HTTP
2749+
// and RPC layers encode it against OrchestrationShellSnapshot on the
2750+
// way out, like the per-item shells from getThreadShellById.
2751+
return {
27502752
snapshotSequence: computeSnapshotSequence(stateRows),
27512753
projects: Arr.filterMap(projectRows, (row) =>
27522754
row.deletedAt === null
@@ -2800,15 +2802,7 @@ pending_approval_requests AS (
28002802
: Result.failVoid,
28012803
),
28022804
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
2803-
};
2804-
2805-
return yield* decodeShellSnapshot(snapshot).pipe(
2806-
Effect.mapError(
2807-
toPersistenceDecodeError(
2808-
"ProjectionSnapshotQuery.getShellSnapshot:decodeShellSnapshot",
2809-
),
2810-
),
2811-
);
2805+
} satisfies OrchestrationShellSnapshot;
28122806
}),
28132807
),
28142808
Effect.mapError((error) => {
@@ -2941,7 +2935,7 @@ pending_approval_requests AS (
29412935
sessionRows.map((row) => [row.threadId, mapSessionRow(row)] as const),
29422936
);
29432937

2944-
const snapshot = {
2938+
return {
29452939
snapshotSequence: computeSnapshotSequence(stateRows),
29462940
projects: Arr.filterMap(projectRows, (row) =>
29472941
row.deletedAt === null && activeProjectIds.has(row.projectId)
@@ -2991,15 +2985,7 @@ pending_approval_requests AS (
29912985
planProgress: threadPlanProgress.getThreadPlanProgress(row.threadId),
29922986
})),
29932987
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
2994-
};
2995-
2996-
return yield* decodeShellSnapshot(snapshot).pipe(
2997-
Effect.mapError(
2998-
toPersistenceDecodeError(
2999-
"ProjectionSnapshotQuery.getArchivedShellSnapshot:decodeShellSnapshot",
3000-
),
3001-
),
3002-
);
2988+
} satisfies OrchestrationShellSnapshot;
30032989
}),
30042990
),
30052991
Effect.mapError((error) => {

0 commit comments

Comments
 (0)