From 5e95d1ea0b0a0377dabb588f084ff6cc8291553b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Tue, 9 Jan 2024 22:31:36 +0000 Subject: [PATCH 1/4] fix: create index on events --- .../202401092201_add_events_id_index.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 migrations/202401092201_add_events_id_index.go diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go new file mode 100644 index 00000000..21a8842d --- /dev/null +++ b/migrations/202401092201_add_events_id_index.go @@ -0,0 +1,21 @@ +package migrations + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// Create a composite index to improve performance of summing payments in the current budget period +var _202401092201_add_events_id_index = &gormigrate.Migration{ + ID: "202401092201_add_events_id_index", + Migrate: func(tx *gorm.DB) error { + + var sql string + sql = "CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)" + + return tx.Exec(sql).Error + }, + Rollback: func(tx *gorm.DB) error { + return nil + }, +} From 6626a480ba71eeb5d855c8ef6e88364d5dd2d65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Tue, 9 Jan 2024 23:28:13 +0000 Subject: [PATCH 2/4] fix: add migration to migration list --- migrations/migrate.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations/migrate.go b/migrations/migrate.go index a3281a89..771b10ff 100644 --- a/migrations/migrate.go +++ b/migrations/migrate.go @@ -11,7 +11,8 @@ func Migrate(db *gorm.DB) error { _202309271616_initial_migration, _202309271617_fix_preimage_null, _202309271618_add_payment_sum_index, + _202401092201_add_events_id_index, }) return m.Migrate() -} \ No newline at end of file +} From 20e10f5ee6910eaffd9b35d83de7a760898106a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Tue, 9 Jan 2024 23:30:32 +0000 Subject: [PATCH 3/4] fix: sql --- migrations/202401092201_add_events_id_index.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go index 21a8842d..8458e107 100644 --- a/migrations/202401092201_add_events_id_index.go +++ b/migrations/202401092201_add_events_id_index.go @@ -9,11 +9,7 @@ import ( var _202401092201_add_events_id_index = &gormigrate.Migration{ ID: "202401092201_add_events_id_index", Migrate: func(tx *gorm.DB) error { - - var sql string - sql = "CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)" - - return tx.Exec(sql).Error + return tx.Exec("CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)").Error }, Rollback: func(tx *gorm.DB) error { return nil From 11bbaf9ba9a8e2748c3ecc3adc386a74516c734c Mon Sep 17 00:00:00 2001 From: Roland <33993199+rolznz@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:48:40 +0700 Subject: [PATCH 4/4] Update migrations/202401092201_add_events_id_index.go --- migrations/202401092201_add_events_id_index.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go index 8458e107..7b2ef48e 100644 --- a/migrations/202401092201_add_events_id_index.go +++ b/migrations/202401092201_add_events_id_index.go @@ -5,7 +5,7 @@ import ( "gorm.io/gorm" ) -// Create a composite index to improve performance of summing payments in the current budget period +// Create a composite index to improve performance of finding the latest nostr event for an app var _202401092201_add_events_id_index = &gormigrate.Migration{ ID: "202401092201_add_events_id_index", Migrate: func(tx *gorm.DB) error {