mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
Merge pull request #333 from Hestia-Homes/migration/material-active-index
Some checks are pending
Test Suite / unit-tests (push) Waiting to run
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:
commit
861bf144ae
4 changed files with 11671 additions and 2 deletions
1
src/app/db/migrations/0247_glorious_darkhawk.sql
Normal file
1
src/app/db/migrations/0247_glorious_darkhawk.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
CREATE INDEX "idx_material_active" ON "material" USING btree ("id") WHERE "material"."is_active";
|
||||
11654
src/app/db/migrations/meta/0247_snapshot.json
Normal file
11654
src/app/db/migrations/meta/0247_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -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">;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue