Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): find in a long thread no longer re-parses every message on each keystroke #20801

Mergedbompus(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/20801/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 25 additions and 1 deletion.

x
0 of 2 viewed, 2 left
22 additions and 0 deletionsapps/server/src/orchestration-v2/ThreadFind.test.tsModified
View file
@@ -456,6 +456,28 @@
}).pipe(Effect.provide(layerTest)),
​
+ it.effect("reuses parses across queries in a thread of a few hundred messages", () =>
+ Effect.gen(function* () {
+ const projection = yield* setup;
+ const total = 600;
+ yield* putItems(
+ Array.from({ length: total }, (_, i) => item(`long:${i}`, i + 1, `message ${i} needle`)),
+ );
+ const parse = vi.spyOn(ThreadFindText, "searchableMessageSegments");
+ try {
+ const first = yield* projection.searchThread({ threadId, query: "needle" });
+ assert.equal(first.totalMatches, total);
+ assert.equal(parse.mock.calls.length, total);
+ parse.mockClear();
+ const typed = yield* projection.searchThread({ threadId, query: "message 5" });
+ assert.equal(typed.totalMatches, 111);
+ assert.equal(parse.mock.calls.length, 0);
+ } finally {
+ parse.mockRestore();
+ }
+ }).pipe(Effect.provide(layerTest)),
+ );
+​
it.effect("searches visible rendered messages and plans in canonical item order", () =>
Effect.gen(function* () {
const projection = yield* setup;