mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-07-19 17:02:59 +00:00
The reporting 'where the money goes' panel joins the latest plan per property to its recommendations ON plan_id, filters to the default active set, and sums estimated_cost / counts property_id per measure_type. The only plan_id index (idx_recommendation_plan_id) is plain, so the aggregate heap-fetches every recommendation to apply the filter and read those columns — hundreds of thousands of fetches on large portfolios (434), which times the panel out. idx_recommendation_plan_default carries plan_id + measure_type + property_id + estimated_cost as key columns (drizzle-orm has no INCLUDE), partial on default = true AND already_installed = false, so the aggregate runs index-only. Added to the schema and generated via drizzle-kit. OPS: build CONCURRENTLY out-of-band on prod before the migration runs so it no-ops there (0258 pattern); the migration uses IF NOT EXISTS for fresh environments. See the migration file header. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| migrations | ||
| schema | ||
| sql | ||
| surveyDB | ||
| backfill-recommendation-denormalization.ts | ||
| create_user.ts | ||
| db.ts | ||
| migrate.ts | ||
| run-sql.ts | ||