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
@@ -9,7 +9,15 @@ function taskIdentity(value){const item=identity(value);if(!item.source||!item.t
|
||||
// A legacy row with no native portal source is ambiguous. Treat it as an
|
||||
// overlapping namespace, never guess v4/v8 and create a second notification.
|
||||
function sameTask(a,b){a=identity(a);b=identity(b);return !!a.source&&!!a.taskId&&a.source===b.source&&a.taskId===b.taskId&&(!a.portalSource||!b.portalSource||a.portalSource===b.portalSource);}
|
||||
function records(store,kind,value){return store.all(kind).filter(row=>sameTask(row,value));}
|
||||
function records(store,kind,value){
|
||||
const context=require('./read-context.cjs').state(store);if(!context)return store.all(kind).filter(row=>sameTask(row,value));
|
||||
const key=item=>JSON.stringify([item.source,item.taskId]),index=context.index('task:'+kind,()=>{
|
||||
const groups=new Map();for(const row of store.all(kind)){const item=identity(row);if(!item.source||!item.taskId)continue;const k=key(item);if(!groups.has(k))groups.set(k,[]);groups.get(k).push(row);}return groups;
|
||||
});
|
||||
// Keep all portal variants: a legacy row without portalSource overlaps every
|
||||
// native namespace, and lookup must still reject multiple matching records.
|
||||
return (index.get(key(identity(value)))||[]).filter(row=>sameTask(row,value));
|
||||
}
|
||||
function lookup(store,kind,value){const rows=records(store,kind,value);if(rows.length>1)fail('同一通知任务存在多条旧记录,须人工核验,禁止新建或自动合并。',409);return rows[0]||null;}
|
||||
function normalize(value){const row=structuredClone(value);for(const key of ['connectionId','source','portalSource','instanceId','taskId','revision'])if(row[key]!==undefined&&row[key]!==null)row[key]=text(row[key]);if(!text(row.revision))delete row.revision;return row;}
|
||||
function fingerprint(value){const row=normalize(value);delete row.connectionId;return digest(row);}
|
||||
|
||||
Reference in new issue
Block a user