fix(tradein): 030 — UNIQUE constraint on avito_imv_evaluations.cache_key (unblocks PR #452) #454
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#454
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/tradein-imv-cache-key-unique"
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
Hotfix миграции 018 (Stage 1 of Avito Scraper v2). Закрывает 🔴 blocker от deep-code-review на PR #452 (#452 (comment)).
Problem
Миграция
018_avito_imv_evaluations.sqlсоздала только non-uniqueimv_cache_key_idx. Ноsave_imv_evaluation(avito_imv.py:481) использует:Это требует UNIQUE/exclusion constraint. Иначе runtime error:
Live impact: первый
POST /api/v1/trade-in/estimateс IMV-compatible payload →save_imv_evaluationfails → caught by gracefulexcept Exceptionв_get_or_fetch_imv_cached→ cache never populates → каждый subsequent call re-fetches от Avito (rate-limit risk + 2-5s latency).Fix
Новая миграция
030_avito_imv_cache_key_unique.sql:IF NOT EXISTS)CONCURRENTLY— таблица свежая (cache_key никогда не записывался до PR #452)Test plan
pg_indexesсодержитimv_cache_key_uniq_idximv: fresh recommended=...(first call) иimv: cache HIT(re-call)Refs
018_avito_imv_evaluations.sql(Stage 1, PR #440 merged)Merged via deep-code-reviewer — verdict APPROVE.
Verification summary:
030_avito_imv_*runs before030_listings_*)imv_cache_key_idx(composite, lookup) and newimv_cache_key_uniq_idx(UNIQUE for ON CONFLICT) are complementary — keep bothavito_imv.py:498ON CONFLICT (cache_key) now resolvablePost-merge unblock chain for user:
deploy-tradein.ymltriggers automatically (pathtradein-mvp/**matches)→ Migration: 030_avito_imv_cache_key_unique.sql(runs before 030_listings_alter_yandex.sql lexicographically)SELECT indexname FROM pg_indexes WHERE tablename='avito_imv_evaluations'→imv_cache_key_uniq_idxpresentPOST /api/v1/trade-in/estimatetwice within 24h → second call logsimv: cache HIT