Skip to content

Commit

Permalink
stores: add index on transaction timestamp (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan authored Nov 27, 2023
1 parent 9575998 commit a57dd96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions stores/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ func performMigrations(db *gorm.DB, logger *zap.SugaredLogger) error {
return performMigration00032_objectIndices(tx, logger)
},
},
{
ID: "00033_transactionsTimestampIndex",
Migrate: func(tx *gorm.DB) error {
return performMigration00033_transactionsTimestampIndex(tx, logger)
},
},
}
// Create migrator.
m := gormigrate.New(db, gormigrate.DefaultOptions, migrations)
Expand Down Expand Up @@ -1429,3 +1435,16 @@ func performMigration00032_objectIndices(txn *gorm.DB, logger *zap.SugaredLogger
logger.Info("migration 00032_objectIndices complete")
return nil
}

func performMigration00033_transactionsTimestampIndex(txn *gorm.DB, logger *zap.SugaredLogger) error {
logger.Info("performing migration 00033_transactionsTimestampIndex")

if err := txn.Table("transactions").Migrator().AutoMigrate(&struct {
Timestamp int64 `gorm:"index:idx_transactions_timestamp"`
}{}); err != nil {
return err
}

logger.Info("migration 00033_transactionsTimestampIndex complete")
return nil
}
2 changes: 1 addition & 1 deletion stores/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type (
TransactionID hash256 `gorm:"unique;index;NOT NULL;size:32"`
Inflow currency
Outflow currency
Timestamp int64
Timestamp int64 `gorm:"index:idx_transactions_timestamp"`
}

outputChange struct {
Expand Down

0 comments on commit a57dd96

Please sign in to comment.