fix(discovery): wire actual retarget + fix named candidate join #695
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/retroactive-retarget-and-matching"
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?
Summary
Fix two fundamental bugs in
ClassInstanceService.applyAutoApprovalRetrospectively().Fix 1: Wire actual retarget into retrospective run
Before:
applyAutoApprovalRetrospectively()calledcountUnmatchedPendingCandidates()- a stub that just counted rows without doing anything.After: Now calls
retargetUnnamedCandidatesToNamedPeople()which performs density-clustering matching to retarget unnamed face candidates to named local or shared people.Fix 2: Fix broken LIKE join in named candidate matching
Before:
For face_detection candidates,
occurrence_refscontains[{"mediaItemId":"..."}]- never the face annotation UUID. The join always failed → 0 named candidates ever matched.After:
Uses new PostgreSQL function
media_item_id_from_occurrence_refs()(V120 migration) with H2 test equivalent (H2MediaItemIdExtractor).Same fix applied to 5 additional LIKE joins in
ClassInstanceService.java:tentativeAssignments()line ~4120acceptGenericNamedCandidate()line ~4252pendingGenericPeopleCandidateIdsForMedia()line ~4400Impact
12,843 pending candidates can now actually be retargeted (instead of just counted). Named auto-approval candidates are correctly found for retrospective runs.
Files changed
ClassInstanceService.java- wire retarget call + 6 SQL join fixesV120__media_item_id_from_occurrence_refs_function.sql- PostgreSQL functionH2MediaItemIdExtractor.java- H2-compatible alias for testsClassInstanceServiceTest.java- register H2 aliasVerification
Fix 1: applyAutoApprovalRetrospectively() now calls retargetUnnamedCandidatesToNamedPeople() instead of the stub countUnmatchedPendingCandidates(). The method was dead code; this change wires it in so unnamed candidates get density-clustering retargeted to named local or shared people instead of being silently counted and discarded. Fix 2: Replace broken LIKE join that searched for dr.id inside the JSONB occurrence_refs array. For face_detection candidates, occurrence_refs contains [{"mediaItemId":"..."}] — never contains the face annotation UUID. The LIKE always failed → 0 named candidates ever matched. Fix: join on mediaItemId via media_item_id_from_occurrence_refs() function (uses JSONB array index 0 → mediaItemId field, matching across both H2 test DB and PostgreSQL production). Impact: 12,843 pending candidates can now actually be retargeted (instead of just counted). Named auto-approval candidates are correctly found for retrospective runs. Changes: - ClassInstanceService.java: wire retarget call + 6 SQL join fixes - V120__media_item_id_from_occurrence_refs_function.sql: PG function - H2MediaItemIdExtractor.java: H2-compatible alias - ClassInstanceServiceTest.java: register H2 alias