Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(clients): thread search reuses per-thread fields across keystrokes #26936

Mergedhieu-lee(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/26936/headmerged by maria-rcks View on GitHub

Showing 3 changed files with 41 additions and 0 deletions (loading 1).

x
0 of 3 viewed, 3 left
4 additions and 0 deletionspackages/client-runtime/src/state/threadSearch.test.tsModified
View file
@@ -191,6 +191,10 @@
threadSearchSubject({ ...thread, id: ThreadId.make("thread-unrecorded"), opens: null }, null)
.opens,
).toEqual({ openedAt: 6_000, score: 1, picks: [] });
+ // A subject built before the open does not hide it.
+ claimThreadOpen(envA, "thread-local", 7_000);
+ expect(threadSearchSubject(thread, null).opens?.openedAt).toBe(7_000);
+ expect(threadSearchSubject(thread, "Project").projectTitle).toBe("Project");
});
​
it("counts recency from what the user wrote, else from when the thread began", () => {
37 additions and 0 deletionspackages/client-runtime/src/state/threadSearch.tsModified
View file
@@ -29,6 +29,7 @@
// When this client last opened each thread, sent or not, so recent threads
// follow quick switches the server merges.
const localThreadOpens = new Map<string, number>();
+let localThreadOpensVersion = 0;
/**
* Records that this client opened a thread, and says whether to send the open
* to the server now.
@@ -36,6 +37,7 @@
export function claimThreadOpen(environmentId: EnvironmentId, threadId: string, now: number) {
const key = `${environmentId}:${threadId}`;
localThreadOpens.set(key, now);
+ localThreadOpensVersion += 1;
if (now - (sentThreadOpens.get(key) ?? Number.NEGATIVE_INFINITY) < THREAD_OPEN_DEDUPE_MS) {