fix(tradein): implement listings_snapshots + offer_price_history writers (#567) #624

Merged
Light1YT merged 2 commits from fix/567-cian-history-writers into main 2026-05-28 13:49:53 +00:00
Owner

Summary

  • listings_snapshots writer was absent — added snapshot_writer.py (idempotent upsert on (listing_id, snapshot_date)).
  • offer_price_history ON CONFLICT now names the unique constraint.
  • Snapshot writes wrapped in begin_nested() SAVEPOINT (fault-tolerant).
  • 17 unit tests.

Note: full-volume populate happens post-deploy via the scheduler PR (#560).

Test plan

  • 17 unit tests pass
  • snapshots populate after a scheduled cian run

Closes #567

## Summary - listings_snapshots writer was absent — added snapshot_writer.py (idempotent upsert on (listing_id, snapshot_date)). - offer_price_history ON CONFLICT now names the unique constraint. - Snapshot writes wrapped in begin_nested() SAVEPOINT (fault-tolerant). - 17 unit tests. Note: full-volume populate happens post-deploy via the scheduler PR (#560). ## Test plan - [x] 17 unit tests pass - [ ] snapshots populate after a scheduled cian run Closes #567
Light1YT added 2 commits 2026-05-28 13:44:22 +00:00
listings_snapshots не имел ни одного writer'а — таблица оставалась пустой.
offer_price_history уже писался в save_detail_enrichment, но ON CONFLICT DO NOTHING
не указывал имя constraint'а (добавлено в 047_cian_history_sanitize.sql), что делало
де-дупликацию неэффективной.

Добавлено:
- snapshot_writer.py: upsert_listing_snapshot() — атомарный INSERT ... ON CONFLICT
  DO UPDATE на (listing_id, snapshot_date), без commit (commit у caller'а).
- base.py save_listings(): вызывает upsert_listing_snapshot после каждого INSERT/UPDATE
  listings; принимает опциональный run_id; ошибка snapshot не прерывает батч.
- cian_detail.py save_detail_enrichment(): SELECT price_rub/price_per_m2 из listings,
  затем upsert_listing_snapshot; ON CONFLICT для offer_price_history теперь ссылается
  на offer_price_history_listing_change_uq (именованный constraint из мигр. 047).
- test_snapshot_writer.py: 17 unit-тестов покрывают SQL-форму, params, идемпотентность,
  интеграцию с save_listings и save_detail_enrichment, fault-tolerance.
Light1YT merged commit ec26e5813f into main 2026-05-28 13:49:53 +00:00
Light1YT deleted branch fix/567-cian-history-writers 2026-05-28 13:49:53 +00:00
Sign in to join this conversation.
No reviewers
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: lekss361/gendesign#624
No description provided.