fix(web): picker reuses the card's person-ranking prefetch #1088

Merged
chris merged 2 commits from fix/picker-ranking-cache into main 2026-10-10 15:13:36 +02:00
Owner

Problem

Tapping "choose an existing person / choose another person" in discovery suggestions showed "Loading people…" for a long time, even though the card view had already fetched the same person-ranking data. The prefetch cache was written on card load but never read when the picker opened.

Fix

  • fetchCandidatePickerRows is now cache-first: it reuses the card's person-ranking prefetch instead of re-requesting.
  • Track in-flight requests in candidateLiveRankingRequests (Map) so concurrent opens dedupe to a single network request.
  • On fetch failure the cache entry is not kept, so a retry re-requests (semantic change vs. the old always-fetch path — a failure no longer pins a stale/absent result).
  • Fixed a stale comment referring to the removed single-centroid ranking.

Verification

  • svelte-check: 0 errors (22 pre-existing warnings)
  • vitest: 71 passed
  • Playwright: 230 passed
  • 2 new regression tests, proven to fail on pre-fix code (they exercise the dedupe/cache reuse).

Scope

Frontend-only; pairs with the backend PR (fix/person-ranking-picker-latency) which removes the server-side N+1. No schema or API changes.

## Problem Tapping "choose an existing person / choose another person" in discovery suggestions showed "Loading people…" for a long time, even though the card view had **already fetched** the same person-ranking data. The prefetch cache was written on card load but **never read when the picker opened**. ## Fix - `fetchCandidatePickerRows` is now **cache-first**: it reuses the card's person-ranking prefetch instead of re-requesting. - Track in-flight requests in `candidateLiveRankingRequests` (Map) so concurrent opens dedupe to a single network request. - On fetch failure the cache entry is not kept, so a retry re-requests (semantic change vs. the old always-fetch path — a failure no longer pins a stale/absent result). - Fixed a stale comment referring to the removed single-centroid ranking. ## Verification - svelte-check: **0 errors** (22 pre-existing warnings) - vitest: **71 passed** - Playwright: **230 passed** - 2 new regression tests, **proven to fail on pre-fix code** (they exercise the dedupe/cache reuse). ## Scope Frontend-only; pairs with the backend PR (fix/person-ranking-picker-latency) which removes the server-side N+1. No schema or API changes.
Opening the merge pickers (choose an existing person / choose a different
person / merge into another person) always re-issued getCandidatePersonRanking
even though the page-load card prefetch had already fetched the same rows, so
the picker showed 'Loading people…' on data the client already held.

- fetchCandidatePickerRows is cache-first: when liveCandidateRankingRows holds
  the candidate's rows it returns them with no network call. The cache stores
  UNFILTERED rows while the picker contract is named-only, so
  hasNamedDisplayName is applied to the cached rows on read; a cold candidate
  fetches exactly as before (live ranking, then the class-instances fallback
  on 404/failure/empty).
- replaced the liveCandidateRankingRequested Set with a shared
  Map<candidateId, Promise<PickerRow[] | null>>: the card prefetch and both
  picker paths await the SAME request, so opening a picker mid-prefetch costs
  no duplicate request. A 'no ranking' outcome or a rejection is dropped from
  the map, so a transient failure is never cached as permanent and a later
  open retries.
- corrected the liveTopNamedRow gate comment: since V156 / ADR 0109 the
  ranking uses the persisted multi-representant pessimistic metric, not the
  old single-centroid one; the gate exists to keep a NAMED stored target
  authoritative for card/dialog titles. Gating behavior is unchanged, and the
  page-load prefetch effect stays gated to unnamed-target match cards.
test(web): pin picker/person-ranking request dedupe
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 4m33s
644cfe2ab8
Two Playwright cases in the discovery-review spec (unnamed stored target, so
the card prefetch IS fired):

- picker opened after the prefetch resolved renders the ranking rows from the
  warm cache with ZERO additional person-ranking requests;
- picker opened while the prefetch is still in flight (response held by a
  gate) shows 'Loading people…', then resolves from that same request —
  exactly one person-ranking request in total.

Both fail on the pre-fix code with rankingRequests === 2.
chris merged commit f00cedf7fb into main 2026-10-10 15:13:36 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1088
No description provided.