From b16d5b749e8252395f769c0c395091bdc6b40aec Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 8 May 2024 14:34:22 -0500 Subject: [PATCH] Add a created_at, kind index for the global feed --- src/db/migrations/011_kind_author_index.ts | 2 +- .../migrations/018_events_created_at_kind_index.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/db/migrations/018_events_created_at_kind_index.ts diff --git a/src/db/migrations/011_kind_author_index.ts b/src/db/migrations/011_kind_author_index.ts index 3e7d010..c41910b 100644 --- a/src/db/migrations/011_kind_author_index.ts +++ b/src/db/migrations/011_kind_author_index.ts @@ -4,7 +4,7 @@ export async function up(db: Kysely): Promise { await db.schema .createIndex('idx_events_kind_pubkey_created_at') .on('events') - .columns(['kind', 'pubkey', 'created_at']) + .columns(['kind', 'pubkey', 'created_at desc']) .execute(); } diff --git a/src/db/migrations/018_events_created_at_kind_index.ts b/src/db/migrations/018_events_created_at_kind_index.ts new file mode 100644 index 0000000..8e6c67c --- /dev/null +++ b/src/db/migrations/018_events_created_at_kind_index.ts @@ -0,0 +1,14 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createIndex('idx_events_created_at_kind') + .on('events') + .columns(['created_at desc', 'kind']) + .ifNotExists() + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.dropIndex('idx_events_created_at_kind').ifExists().execute(); +}