Merge pull request #333 from Hestia-Homes/migration/material-active-index
Some checks are pending
Test Suite / unit-tests (push) Waiting to run

Add partial index on material(is_active) for the catalogue read
This commit is contained in:
KhalimCK 2026-06-29 14:16:22 +01:00 committed by GitHub
commit 861bf144ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11671 additions and 2 deletions

View file

@ -0,0 +1 @@
CREATE INDEX "idx_material_active" ON "material" USING btree ("id") WHERE "material"."is_active";

File diff suppressed because it is too large Load diff

View file

@ -1723,6 +1723,13 @@
"when": 1782498864047,
"tag": "0246_minor_lady_bullseye",
"breakpoints": true
},
{
"idx": 247,
"version": "7",
"when": 1782730761916,
"tag": "0247_glorious_darkhawk",
"breakpoints": true
}
]
}

View file

@ -1,4 +1,4 @@
import { InferModel } from "drizzle-orm";
import { InferModel, sql } from "drizzle-orm";
import {
bigserial,
text,
@ -8,6 +8,7 @@ import {
pgEnum,
json,
boolean,
index,
} from "drizzle-orm/pg-core";
export const MaterialType: [string, ...string[]] = [
@ -125,6 +126,12 @@ export const material = pgTable("material", {
includesScaffolding: boolean("includes_scaffolding").default(false),
includesBattery: boolean("includes_battery").default(false),
batterySize: real("battery_size"),
});
}, (table) => [
// The modelling_e2e Lambda reads the active catalogue once per invocation
// (WHERE is_active ORDER BY id). Without this index that is a full seq scan
// every time (~23ms, ×32 concurrent at startup). Partial on id so the active
// rows come back already id-ordered — no sort, no filter.
index("idx_material_active").on(table.id).where(sql`${table.isActive}`),
]);
export type Material = InferModel<typeof material, "select">;