Scoped per-receipt alias resolution (stop loading the full table) #17
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/scoped-alias-pipeline"
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?
merchant_aliases(the line→group table) is shared reference data — one row per distinct product line per merchant, across all users. It can grow to millions of rows, yet the app loaded the entire table into every client on hydrate andmapAndBookdid a linear.find()over it. This resolves aliases scoped to each scan instead, index-backed by the(merchant_id, normalized_string)primary key.Changes
dbFetchAliasesFor(merchantId, normalizedStrings)— fetches only the rows for a receipt's merchant + line strings (≤ #lines, index-backed).dbFetchAllAliases(limit)for the admin allocate board (capped + logged — no silent truncation).fetchAllDatano longer loadsmerchant_aliases; the in-store catalog starts empty.addScannedReceipt/runPipeline/confirmGroupare now async —harmonize→ fetch scoped aliases →mapAndBookagainst just those.loadAllAliases()populates the catalog for the admin board, which loads it on mount.mapAndBookstays pure, it just receives a small scoped array.Why it also fixes the "new scan doesn't pick up changes" report
Every scan now reads the current DB rows for its lines, so group/alias edits show up without an app restart — previously the in-memory catalog only refreshed on hydrate (launch/sign-in).
Cost
O(receipt size), not O(table size) — independent of total alias count.
Follow-up
The admin allocate "All" view still loads the (capped) catalog client-side; at scale it needs server-side pagination/search.
tsc clean · 52/52 booking tests · lint clean
🤖 Generated with Claude Code