@secondlayer/shared 6.8.0 → 6.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
// Composite index backing the l2-decoder /health freshness probe
|
|
4
|
+
// (`readLatestDecodedAt`): `WHERE event_type = ? AND canonical = ?
|
|
5
|
+
// ORDER BY created_at DESC LIMIT 1`. Without it that query seq-scans the
|
|
6
|
+
// full decoded_events table (~18GB) and sorts millions of rows per call;
|
|
7
|
+
// /health fans it out per decoder, so under load Postgres pinned several
|
|
8
|
+
// cores. With this index it's an instant index-only scan.
|
|
9
|
+
//
|
|
10
|
+
// Already created CONCURRENTLY on prod; IF NOT EXISTS makes this a no-op
|
|
11
|
+
// there and a cheap build on fresh/dev databases (small data).
|
|
12
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await sql`CREATE INDEX IF NOT EXISTS decoded_events_evt_canon_created_idx ON decoded_events (event_type, canonical, created_at DESC)`.execute(
|
|
14
|
+
db,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
19
|
+
await sql`DROP INDEX IF EXISTS decoded_events_evt_canon_created_idx`.execute(
|
|
20
|
+
db,
|
|
21
|
+
);
|
|
22
|
+
}
|