feat(tradein): search matview + indexes (Phase 3.1) #469

Merged
lekss361 merged 2 commits from feat/tradein-search-matview into main 2026-05-23 14:01:18 +00:00
2 changed files with 5 additions and 2 deletions
Showing only changes of commit 09698c5124 - Show all commits

View file

@ -26,7 +26,10 @@ def refresh_search_matview() -> None:
Logs duration. Idempotent. Safe to run during read traffic (CONCURRENTLY).
"""
start = time.monotonic()
dsn = settings.database_url # psycopg v3 accepts postgresql:// DSN
# DATABASE_URL is SQLAlchemy dialect form (postgresql+psycopg://...) in tradein-mvp
# (see tradein-mvp/docker-compose.prod.yml). libpq / psycopg.connect() accepts only
# postgresql:// or postgres:// — strip the +psycopg dialect prefix.
dsn = settings.database_url.replace("postgresql+psycopg://", "postgresql://", 1)
with psycopg.connect(dsn, autocommit=True) as conn:
with conn.cursor() as cur:
cur.execute("REFRESH MATERIALIZED VIEW CONCURRENTLY listings_search_mv")

View file

@ -130,7 +130,7 @@ SELECT
h.house_class,
h.developer_name,
h.rating AS house_rating,
h.ratings_count AS house_ratings_count,
h.reviews_count AS house_ratings_count,
-- Cross-source aggregates
(SELECT count(*) FROM listing_sources ls WHERE ls.listing_id = l.id) AS source_count,
(SELECT array_agg(DISTINCT ext_source) FROM listing_sources ls WHERE ls.listing_id = l.id) AS sources,