Forráskód Böngészése

Read old review fee evidence in bounded parallel batches

彭峰 4 órája
szülő
commit
d59e116add
1 módosított fájl, 12 hozzáadás és 3 törlés
  1. 12 3
      scripts/cloud/legacy-direct-control.js

+ 12 - 3
scripts/cloud/legacy-direct-control.js

@@ -35,11 +35,16 @@ async function directReviewFeeProof(co,rows,includePending=false) {
   LEFT JOIN "LegacyReviewSyncState" s ON s.company=m.company AND s."taskId"=m."objectId"
   WHERE c.company=$1 AND c."modelId"=60 AND c."generalId"=ANY($2::numeric[]) AND m.fxzt='1'
   AND ($3 OR NOT COALESCE(s."pendingIncome",false)) AND v.status IN ('historical','exception')
-  AND (v."incomeMonth">='2026-09' OR xs_legacy_review_needs_fee(m.company,m."objectId"))
+  AND (v."incomeMonth">='2026-09' OR EXISTS(
+   SELECT 1 FROM "CommonModel" o JOIN "CourseAppointment" a ON a.company=o.company AND a.id=o."itemId"
+   WHERE o.company=m.company AND o."modelId"=54 AND a.szyh::text=m.yhid::text AND a.dslx::text='3'
+   AND o."generalId"=CASE WHEN m."orderId"::text ~ '^[1-9][0-9]*$' THEN m."orderId"::numeric END
+  ))
   AND r."completionRole"='historical_unknown'`,[co,ids,includePending]);
  const verified=new Set(),zeros=new Map(),trials=new Map(),fields=['yhid','plid','xxjlid','orderId','kcid','fxzt','wcsj','kywrq','kywsj'];
- const deadline=Date.now()+15000;
- for(const coach of new Set(candidates.map(row=>Number(row.coachId)))){
+ const deadline=Date.now()+24000;
+ const coaches=[...new Set(candidates.map(row=>Number(row.coachId)))];
+ async function readCoachFees(coach){
   const coachIds=new Set(candidates.filter(row=>Number(row.coachId)===coach).map(row=>Number(row.generalId)));
   const income=new Map();
   let total, count, read=0;
@@ -70,6 +75,10 @@ async function directReviewFeeProof(co,rows,includePending=false) {
    console.warn(JSON.stringify({event:'legacy_review_income_proof_unavailable',coach}));
   }
  }
+ // A slow coach account must not consume the whole source page's proof budget.
+ for(let i=0;i<coaches.length&&Date.now()<deadline;i+=3){
+  await Promise.all(coaches.slice(i,i+3).map(readCoachFees));
+ }
  if(zeros.size){
   const zeroRows=rows.filter(row=>zeros.has(Number(row.GeneralID??row.generalId)));
   try{