feat(tradein): search matview + indexes (Phase 3.1) #469
2 changed files with 5 additions and 2 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue