perf(webui): restore cached threads and load mention catalogs on demand
This commit is contained in:
1 parent
c370e2a5a5
commit
1a78ae2b99
13 files changed
+316
-65
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { MemoryLruCache } from "./memory-lru-cache";
|
||||
import { parseWebuiThreadPayload } from "./api";
|
||||
import { readReloadCache, removeReloadCache, writeReloadCache } from "./reload-cache";
|
||||
import type { WebuiThreadPersistedPayload } from "./types";
|
||||
|
||||
/** Process-local canonical replay cache used for stale-while-revalidate session entry. */
|
||||
/** Bounded canonical replay cache; the most recent snapshot also survives tab reloads. */
|
||||
export class WebuiThreadCache extends MemoryLruCache<WebuiThreadPersistedPayload> {
|
||||
constructor(
|
||||
maxBytes = 16 * 1024 * 1024,
|
||||
@@ -9,6 +11,40 @@ export class WebuiThreadCache extends MemoryLruCache<WebuiThreadPersistedPayload
|
||||
) {
|
||||
super(maxBytes, maxEntries);
|
||||
}
|
||||
|
||||
override get(key: string): WebuiThreadPersistedPayload | undefined {
|
||||
const cached = super.get(key);
|
||||
if (cached) return cached;
|
||||
const stored = readReloadCache("thread");
|
||||
if (!stored || typeof stored !== "object" || !("key" in stored)
|
||||
|| stored.key !== key || !("body" in stored)) return undefined;
|
||||
try {
|
||||
const body = parseWebuiThreadPayload(stored.body);
|
||||
this.set(key, body);
|
||||
return super.get(key);
|
||||
} catch {
|
||||
removeReloadCache("thread");
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
override set(key: string, body: WebuiThreadPersistedPayload): void {
|
||||
super.set(key, body);
|
||||
if (super.get(key)) writeReloadCache("thread", { key, body });
|
||||
}
|
||||
|
||||
override delete(key: string): void {
|
||||
super.delete(key);
|
||||
const stored = readReloadCache("thread");
|
||||
if (stored && typeof stored === "object" && "key" in stored && stored.key === key) {
|
||||
removeReloadCache("thread");
|
||||
}
|
||||
}
|
||||
|
||||
override clear(): void {
|
||||
super.clear();
|
||||
removeReloadCache("thread");
|
||||
}
|
||||
}
|
||||
|
||||
export const webuiThreadCache = new WebuiThreadCache();
|
||||
Reference in new issue
Block a user