Merge pull request #438 from trails-cool/fix/planner-sessions-lastactivity-idx

fix(planner): add index on sessions.last_activity for the expire job
This commit is contained in:
Ullrich Schäfer 2026-05-26 00:03:04 +02:00 committed by GitHub
commit e35a8e27c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
import { pgSchema, text, timestamp, boolean, customType } from "drizzle-orm/pg-core";
import { pgSchema, text, timestamp, boolean, customType, index } from "drizzle-orm/pg-core";
const bytea = customType<{ data: Buffer }>({
dataType() {
@ -16,4 +16,9 @@ export const sessions = plannerSchema.table("sessions", {
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
lastActivity: timestamp("last_activity", { withTimezone: true }).notNull().defaultNow(),
closed: boolean("closed").notNull().default(false),
});
}, (t) => ({
// Hourly `expireSessions()` job runs `DELETE WHERE last_activity < cutoff`.
// Without this index it's a full table scan that grows linearly with
// total sessions ever created.
lastActivityIdx: index("sessions_last_activity_idx").on(t.lastActivity),
}));