Add an index for the list query once you have real traffic. Plugin schemas can’t declare indexes, so each one is a line you add yourself. The examples use drizzle.
The notification list
Every inbox load filters by user and sorts by time:
ts
index("notification_user_created_idx").on(table.userId, table.createdAt)The email sweep
With email routes, the sweep queries notificationDelivery by status and due time:
ts
index("notification_delivery_due_idx").on(table.status, table.scheduledFor)
// only if you use throttle:
index("notification_delivery_throttle_idx").on(table.userId, table.type, table.channel, table.sentAt)Organization cleanup and export
Organization cleanup looks notifications up by org, and export pages through an org’s notifications by time. Both look deliveries up by notification. Postgres doesn’t index foreign keys on its own:
ts
index("notification_org_created_idx").on(table.organizationId, table.createdAt)
index("notification_delivery_notification_idx").on(table.notificationId)
// only if you export without an organizationId:
index("notification_created_idx").on(table.createdAt)