-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Milestone
Description
Track Retrieval Test Coverage per Deal
Summary
Retrieval tests currently choose deals biased toward newest (createdAt DESC), so the same recent deals get tested repeatedly while older/untested deals are skipped. Add per-deal tracking fields and adjust selection to favor never/least-recently-tested deals while keeping provider balancing.
Current Behavior
RetrievalService.selectRandomDealsForRetrieval()loads deals ordered bycreatedAt DESC, takesMath.max(count * 2, 100), groups byspAddress, shuffles within each provider, then selects a balanced set.- No tracking exists for “when was this deal last retrieval-tested” or “how many times has it been tested”.
- Because deals are shuffled within each provider, selection is effectively random within a provider (biased only by the initial “newest deals” cutoff), which makes it hard to improve coverage without changing the approach.
Code: apps/backend/src/retrieval/retrieval.service.ts
Proposed Changes
1) Add retrieval tracking fields to deals
deals.last_retrieved_at TIMESTAMPTZ NULLdeals.retrieval_count INTEGER NOT NULL DEFAULT 0- Index for sorting/filtering:
IDX_deals_last_retrieved_atonlast_retrieved_at(optionally partial:WHERE last_retrieved_at IS NOT NULL)
2) Update selection to prioritize coverage (while keeping provider balancing)
When selecting candidate deals, order by:
lastRetrievedAt ASC NULLS FIRST(never tested first)retrievalCount ASC(lower count first)createdAt DESC(tie-breaker)
Selection approach (keeps provider balancing and preserves priority):
- Query a prioritized candidate set using the ORDER BY above.
- Group candidates by
spAddresswithout reordering (preserve the query order within each provider). - Select a balanced batch by taking from the front of each provider’s list (round-robin or “deals per provider”).
Optional randomness (without losing the coverage bias):
- Only randomize within “equivalent priority” ties inside a provider (e.g., same
retrievalCountand same/NULLlastRetrievedAt), then still take from the front.
3) Update tracking once per deal attempt
After a deal’s retrieval tests finish (success or failure), update:
lastRetrievedAt = NOW()retrievalCount = retrievalCount + 1
Notes:
- Update should run even if all retrieval methods fail (track “attempts”, not just successes).
- Prefer an atomic DB update (
UPDATE ... SET retrieval_count = retrieval_count + 1) to avoid lost updates if concurrent workers can test the same deal.
Implementation Checklist
- Migration: add
last_retrieved_at,retrieval_count, andIDX_deals_last_retrieved_at - Entity: add
lastRetrievedAtandretrievalCountcolumns inapps/backend/src/database/entities/deal.entity.ts - Retrieval selection: replace
createdAt DESCordering with coverage-based ordering, preserve provider balancing - Retrieval tracking update: increment once per deal attempt (not per method), including failure paths
- Rollback: migration
down()cleanly removes index + columns
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
📌 Triage