perf: cache static assets and validate only requested refresh regions
This commit is contained in:
1 parent
f317314a3c
commit
73773f9526
31 files changed
+554
-41
No files matched your search
@@ -32,7 +32,7 @@
|
||||
const submission=window.PageLifecycle?.submission,controller=new AbortController(),cancel=()=>controller.abort(signal.reason);let timedOut=false;
|
||||
if(signal?.aborted)cancel();else signal?.addEventListener('abort',cancel,{once:true});
|
||||
const timer=setTimeout(()=>{timedOut=true;controller.abort();},timeout);
|
||||
try{const response=await fetch('/api/storage/servers'+route,{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(input),signal:controller.signal});const body=await response.json();if(!response.ok)throw new Error(body.error||'存储操作失败。');if(route==='')window.PageLifecycle?.succeeded(submission);return body;}
|
||||
try{window.PageLifecycle?.invalidateRegion?.('storage','orderRules','records','health','home');const response=await fetch('/api/storage/servers'+route,{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(input),signal:controller.signal});const body=await response.json();if(!response.ok)throw new Error(body.error||'存储操作失败。');window.PageLifecycle?.invalidateRegion?.('storage','orderRules','records','health','home');if(route==='')window.PageLifecycle?.succeeded(submission);return body;}
|
||||
catch(error){if(route===''){window.PageLifecycle?.failed(submission);if(timedOut||error instanceof TypeError){api('/storage').then(()=>{if(alive())status.textContent='结果待核实:已查询服务器列表,请核对保存结果;不会自动重试。';}).catch(()=>{});throw new Error('结果待核实:保存响应超时或连接中断,正在查询状态;不会自动重试。');}}if(timedOut)throw new Error('连接超时,请检查网络后重试。');throw error;}
|
||||
finally{clearTimeout(timer);signal?.removeEventListener('abort',cancel);}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user