perf(index): debounce lexical warmup after invalidation paths
This commit is contained in:
@@ -173,6 +173,8 @@ function onSendKeydown(e) {
|
||||
|
||||
let hideApplyTimer = null;
|
||||
const HIDE_APPLY_DEBOUNCE_MS = 250;
|
||||
let lexicalWarmupTimer = null;
|
||||
const LEXICAL_WARMUP_DEBOUNCE_MS = 500;
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
@@ -358,6 +360,7 @@ async function handleAnchorGenerate() {
|
||||
// L1 rebuild only if new chunks were added (usually 0 in normal chat)
|
||||
if (chunkResult.built > 0) {
|
||||
invalidateLexicalIndex();
|
||||
scheduleLexicalWarmup();
|
||||
}
|
||||
|
||||
await sendAnchorStatsToFrame();
|
||||
@@ -623,6 +626,7 @@ async function maybeAutoExtractL0() {
|
||||
// L1 rebuild only if new chunks were added
|
||||
if (chunkResult.built > 0) {
|
||||
invalidateLexicalIndex();
|
||||
scheduleLexicalWarmup();
|
||||
}
|
||||
|
||||
await sendAnchorStatsToFrame();
|
||||
@@ -1003,6 +1007,16 @@ function applyHideStateDebounced() {
|
||||
}, HIDE_APPLY_DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
function scheduleLexicalWarmup(delayMs = LEXICAL_WARMUP_DEBOUNCE_MS) {
|
||||
clearTimeout(lexicalWarmupTimer);
|
||||
const scheduledChatId = getContext().chatId || null;
|
||||
lexicalWarmupTimer = setTimeout(() => {
|
||||
lexicalWarmupTimer = null;
|
||||
if (isChatStale(scheduledChatId)) return;
|
||||
warmupIndex();
|
||||
}, delayMs);
|
||||
}
|
||||
|
||||
async function clearHideState() {
|
||||
// 暴力全量 unhide,确保立刻恢复
|
||||
await unhideAllMessages();
|
||||
@@ -1424,6 +1438,7 @@ async function handleMessageDeleted(scheduledChatId) {
|
||||
}
|
||||
|
||||
invalidateLexicalIndex();
|
||||
scheduleLexicalWarmup();
|
||||
await sendAnchorStatsToFrame();
|
||||
await sendVectorStatsToFrame();
|
||||
|
||||
@@ -1673,6 +1688,8 @@ function unregisterEvents() {
|
||||
events.cleanup();
|
||||
events = null;
|
||||
activeChatId = null;
|
||||
clearTimeout(lexicalWarmupTimer);
|
||||
lexicalWarmupTimer = null;
|
||||
|
||||
$(".xiaobaix-story-summary-btn").remove();
|
||||
hideOverlay();
|
||||
|
||||
Reference in New Issue
Block a user