diff --git a/tradein-mvp/backend/app/tasks/refresh_search_matview.py b/tradein-mvp/backend/app/tasks/refresh_search_matview.py index f177d732..29fc1f8d 100644 --- a/tradein-mvp/backend/app/tasks/refresh_search_matview.py +++ b/tradein-mvp/backend/app/tasks/refresh_search_matview.py @@ -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") diff --git a/tradein-mvp/backend/data/sql/050_search_optimization.sql b/tradein-mvp/backend/data/sql/050_search_optimization.sql index f7989b32..c15ba413 100644 --- a/tradein-mvp/backend/data/sql/050_search_optimization.sql +++ b/tradein-mvp/backend/data/sql/050_search_optimization.sql @@ -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,