perf(api): set-based candidate overlap + batched confirm — remove per-decision N+1 (890 face queries → 2) #821
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/decision-perf-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Every tentative accept/reject ran
extraOverlapCandidateIdswith one SQL query per face-bearing pending candidate (measured: 890 queries on the main owner) plus a 26 MBpayloadJSONB over-fetch;confirmTentativeCandidatesrepeated the full overlap resolution per selected candidate (select-all on a 649-candidate person ≈ 700k statements). Hot reads were already indexed — this was algorithmic, not missing indexes.Changes
pendingCandidateRows: only needed columns (no payload), excludesface_detectionartifacts (media-only refs can never overlap review candidates).confirmTentativeCandidates: single batch pass resolves all per-candidate lock sets once (chunked ref-intersection + candidate read); accept primitive keeps per-row locking/revalidation and per-candidate success semantics.class_instance_occurrences(WHERE state='accepted', predicate chosen so both runtime assignment queries can use it).extraOverlapCandidateIds(List<CandidateSnapshot>, …)default onDomainCandidateDecisionStrategy— only people overrides it; other domains untouched.Tests
CountingJdbcClienttest decorator; constant-statement scan test; one-overlap-resolution confirm test; ref-intersecting-only confirm; differential parity vs. an in-test legacy oracle on a 25-candidate corpus; V134 migration content tests (H2 + Postgres container).dev.memories.api.discovery.*: 464 tests, 0 failures.*Decision*/*Candidate*: 156 tests, 0 failures.Expected effect
Decision POSTs drop from ~890 queries + 26 MB detoast to ~2 batched statements + small refs; multi-select confirm no longer multiplies. Complements #820 (frontend optimistic decisions). Follow-up (separate): R4 recognition re-arm debounce/incrementalization.