perf: streamline rule reads and unblock background discovery

This commit is contained in:
abaishu0730 committed 2026-10-26 16:13:15 +08:00
1 parent b14fa2f4d1
commit b17b975812
19 files changed
+263 -42

No files matched your search

@@ -0,0 +1,23 @@
'use strict';
const {windowForCutoff}=require('./window.cjs');
const eligibility=require('./restricted-test.cjs');
function discoveryBlockers(store,cutoff,allowed=()=>true){
if(!store.executionSources)return (store.deliveryBlockers?.(allowed)||[]).map(id=>'连接 '+id+' 本地执行线索尚未交付。');
const window=cutoff?windowForCutoff(cutoff,store.schedule(),store.calendar()):null;
const relevant=store.all('execution-tasks').filter(task=>!task.removedAt&&!['sent','ignored'].includes(task.status)&&(!window||eligibility.eventInWindow(store,task.row,window)));
const sources=new Set([...store.executionSources(),...relevant.map(task=>task.connectionId)].filter(allowed));
// Inactive sources cannot consume hints. Retain their evidence without
// blocking unrelated work, unless a retained task still needs that source.
const included=id=>sources.has(id);
const blockers=(store.deliveryBlockers?.(included)||[]).filter(included).map(id=>'连接 '+id+' 本地执行线索尚未交付。');
const pendingSources=new Set([...store.all('execution-discoveries'),...store.all('execution-discovery-runs')].filter(hint=>hint.status==='pending'&&included(hint.connectionId)).map(hint=>hint.connectionId));
for(const id of pendingSources)blockers.push('连接 '+id+' 完整对账线索尚未处理。');
if(store.activeDiscoveries>0)blockers.push('待办扫描尚未完成,不能冻结或发送不完整类别。');
for(const id of sources){
const scan=store.get('execution-scans',id);
if(scan?.status!=='complete')blockers.push('连接 '+id+' 尚无完整成功扫描'+(scan?.error?':'+scan.error:'。'));
else if(cutoff&&Date.parse(scan.startedAt)<Date.parse(cutoff))blockers.push('连接 '+id+' 需要截止时点之后启动的完整扫描。');
}
return blockers;
}
module.exports={discoveryBlockers};