Skip to content

Commit

Permalink
Merge pull request #209 from getAlby/fix/index-events
Browse files Browse the repository at this point in the history
feat: new index for latest event by app_id
  • Loading branch information
rolznz authored Jan 10, 2024
2 parents 3289026 + 11bbaf9 commit 1b74154
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions migrations/202401092201_add_events_id_index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package migrations

import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)

// 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 {
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
},
}
3 changes: 2 additions & 1 deletion migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 1b74154

Please sign in to comment.