Skip to content

Commit bd194d3

Browse files
committed
test(sharing): the set-form pins' engine double tests an $in list as a Set
The 10,000-record pin spent 709 of its 736 ms in the double, which rebuilt and scanned each $in list once per row; under CI shard load that passed the 5 s test timeout. Each list is now a Set built once, so a read costs the rows it scans plus the ids it names. The counted-read assertions are unchanged. Claude-Session: https://claude.ai/code/session_01Utp6CbdHk3orAeensH6EzS Co-authored-by: Claude <noreply@anthropic.com>
1 parent 14bf9f9 commit bd194d3

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎packages/plugins/plugin-sharing/src/sharing-service.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,10 +2476,20 @@ function makeVerdictEngine(schemas: Record<string, any>, inert: ReadonlySet<stri
24762476
const members = wanted != null && typeof wanted === 'object' ? (wanted as { $in?: unknown }).$in : [wanted];
24772477
return Array.isArray(members) ? members.map(keyOf).filter((k): k is string => k !== null) : [];
24782478
};
2479+
/**
2480+
* Each `$in` list as a Set, built once per list rather than once per row it is tested
2481+
* against: a read costs the rows it scans plus the ids it names, never rows x ids.
2482+
*/
2483+
const inSets = new WeakMap<object, ReadonlySet<string>>();
24792484
const valueMatches = (actual: unknown, wanted: unknown): boolean => {
24802485
if (wanted != null && typeof wanted === 'object') {
2486+
let members = inSets.get(wanted);
2487+
if (members === undefined) {
2488+
members = new Set(listOf(wanted));
2489+
inSets.set(wanted, members);
2490+
}
24812491
const key = keyOf(actual);
2482-
return key !== null && listOf(wanted).includes(key);
2492+
return key !== null && members.has(key);
24832493
}
24842494
return actual === wanted;
24852495
};

0 commit comments

Comments
 (0)