perf: cache static assets and validate only requested refresh regions

This commit is contained in:
abaishu0730 committed 2026-10-28 12:11:19 +08:00
1 parent f317314a3c
commit 73773f9526
31 files changed
+554 -41

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@
if(running||[...pendingActions.values()].includes(currentId)||turns.some(t=>t.actions?.some(a=>a.status==='running')))watch();
}
async function loadCurrent(signal){if(!currentId)return;const id=currentId,at=revision,c=await api('/assistant/conversations/'+id,undefined,{signal,ownerCheck:live});if(!live()||id!==currentId||at!==revision)return;conversation=c;drawMessages();}
const watcher=window.PageLifecycle.poll(async signal=>{if(!polling)return;polling=false;try{await loadCurrent(signal);}catch(e){if(signal.aborted)polling=true;else showError(e);}},1200,{isActive:live});
const watcher=window.PageLifecycle.regionPoll('assistant',{refresh:async signal=>{if(!polling)return false;polling=false;try{await loadCurrent(signal);}catch(e){polling=true;throw e;}},onError:showError},1200,{isActive:live,enabled:()=>polling});watcher.refreshRegion=async()=>{await window.PageLifecycle.validateRegion('assistant').catch(showError);await refreshList();await loadCurrent();};
function watch(){polling=true;watcher.schedule();}
async function select(id){currentId=id;conversation=null;revision++;sessionStorage.setItem(key,id);drawList();if(id)await loadCurrent();else drawMessages();}
function drawPager(){container.querySelector('#assistant-page').textContent=listPage+' / '+Math.max(1,Math.ceil(listTotal/25));container.querySelector('#assistant-prev').disabled=listPage<=1;container.querySelector('#assistant-next').disabled=listPage*25>=listTotal;}