Merge qualified routine query-accounting repair into PR 18380

Co-Authored-By: Paperclip <noreply@paperclip.ing>

* commit '820101c4cb49d5d1cf7853ffa8601f7c49a634a8':
  test: distinguish status-card candidate and revision reads
  perf(server): stop recurring attention retention scans (#18388)
This commit is contained in:
DottaandPaperclip committed 2026-10-31 13:00:54 -05:00
commit abe9d2ce14
1 file changed
+8 -4
@@ -352,15 +352,19 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu
await flush();
}
await flush();
// One eager reconciliation after idle and one bounded batched continuation;
// the producers themselves are not counted as background SQL.
const dueReads = () => select.mock.calls.filter(([fields]) => fields && "card" in fields && fields.card === statusCards).length;
// One eager reconciliation after idle and one bounded batched continuation.
// Each pass reads candidates once; evaluating its one changed card also
// reads that card's revision for generation CAS. Bound both query classes
// independently; the producers are not counted as background SQL.
const dueReads = () => select.mock.calls.filter(([fields]) => fields && "card" in fields && fields.card === statusCards && !("revision" in fields)).length;
const revisionReads = () => select.mock.calls.filter(([fields]) => fields && "card" in fields && fields.card === statusCards && "revision" in fields).length;
const nextReads = () => select.mock.calls.filter(([fields]) => fields && "at" in fields && fields.at === statusCards.nextEvalAt).length;
const elapsedMs = Date.now() - burstStarted;
const maximum = Math.ceil(elapsedMs / 1000) + 2;
console.info("status-card burst", { elapsedMs, maximum, runs: run.mock.calls.length, due: dueReads(), next: nextReads(), searches: searchedCompanies.length });
console.info("status-card burst", { elapsedMs, maximum, runs: run.mock.calls.length, due: dueReads(), revisions: revisionReads(), next: nextReads(), searches: searchedCompanies.length });
expect(run.mock.calls.length).toBeLessThanOrEqual(maximum);
expect(dueReads()).toBeLessThanOrEqual(maximum); expect(nextReads()).toBeLessThanOrEqual(maximum);
expect(revisionReads()).toBeLessThanOrEqual(maximum);
expect(searchedCompanies.length).toBeLessThanOrEqual(maximum);
expect(searchedCompanies.length).toBeGreaterThan(0);
expect(new Set(searchedCompanies)).toEqual(new Set([originalCompany]));