Skip to content

Commit

Permalink
Improve performance of rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 29, 2024
1 parent d6837ad commit 50d1ac2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions internal/storage/postgres/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

const rollbackQuery = `DELETE FROM ? WHERE height > ? RETURNING id;`
const rollbackQueryWithPartition = `DELETE FROM ? WHERE height > ? AND time > ? RETURNING id;`

// RollbackManager -
type RollbackManager struct {
Expand Down Expand Up @@ -73,6 +74,16 @@ func (rm RollbackManager) Rollback(ctx context.Context, indexerName string, heig
&models.Class{},
&models.StorageDiff{},
&models.Block{},
&models.ProxyUpgrade{},
&models.ClassReplace{},
} {
_, err := tx.Exec(ctx, rollbackQuery, bun.Ident(model.TableName()), height)
if err != nil {
return tx.HandleError(ctx, err)
}
}

for _, model := range []storage.Model{
&models.Invoke{},
&models.Declare{},
&models.Deploy{},
Expand All @@ -83,10 +94,8 @@ func (rm RollbackManager) Rollback(ctx context.Context, indexerName string, heig
&models.Message{},
&models.Fee{},
&models.Transfer{},
&models.ProxyUpgrade{},
&models.ClassReplace{},
} {
deletedCount, err := tx.Exec(ctx, rollbackQuery, bun.Ident(model.TableName()), height)
deletedCount, err := tx.Exec(ctx, rollbackQueryWithPartition, bun.Ident(model.TableName()), height, state.LastTime.AddDate(0, 0, -1))
if err != nil {
return tx.HandleError(ctx, err)
}
Expand Down

0 comments on commit 50d1ac2

Please sign in to comment.