perf: optimize full interface loading and refresh paths
This commit is contained in:
1 parent
649a0df832
commit
f317314a3c
57 files changed
+791
-136
No files matched your search
@@ -66,7 +66,8 @@ async function readRelease(response){
|
||||
}
|
||||
function createUpdateChecker({currentVersion,fetchImpl=globalThis.fetch,apiUrl=RELEASES_API_URL,repositoryUrl=REPOSITORY_URL,timeoutMs=5000}={}){
|
||||
if(!versionParts(currentVersion))throw new Error('当前版本必须是 x.y.z 格式。');
|
||||
return async function checkForUpdate(){
|
||||
let inFlight=null;
|
||||
async function readUpdate(){
|
||||
const base={currentVersion,latest:null};
|
||||
if(typeof fetchImpl!=='function')return {...base,status:'unavailable'};
|
||||
const controller=new AbortController(),timer=setTimeout(()=>controller.abort(),timeoutMs);
|
||||
@@ -76,6 +77,11 @@ function createUpdateChecker({currentVersion,fetchImpl=globalThis.fetch,apiUrl=R
|
||||
return parseRelease(await readRelease(response),currentVersion,{repositoryUrl});
|
||||
}catch{return {...base,status:'unavailable'};}
|
||||
finally{clearTimeout(timer);}
|
||||
}
|
||||
return async function checkForUpdate(){
|
||||
// Share only work still in progress; a later manual check always revalidates.
|
||||
if(!inFlight)inFlight=readUpdate().finally(()=>{inFlight=null;});
|
||||
return structuredClone(await inFlight);
|
||||
};
|
||||
}
|
||||
module.exports={REPOSITORY_URL,RELEASES_API_URL,compareVersions,parseRelease,createUpdateChecker};
|
||||
Reference in new issue
Block a user