mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-11 12:33:41 +00:00
829f4543da
# Which Problems Are Solved On Zitadel cloud we found changing the order of columns in the `eventstore.events2_current_sequence` index improved CPU usage for the `SELECT ... FOR UPDATE` query the pusher executes. # How the Problems Are Solved `eventstore.events2_current_sequence`-index got replaced # Additional Context closes https://github.com/zitadel/zitadel/issues/9082
40 lines
919 B
Go
40 lines
919 B
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"fmt"
|
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
var (
|
|
//go:embed 44/*.sql
|
|
replaceCurrentSequencesIndex embed.FS
|
|
)
|
|
|
|
type ReplaceCurrentSequencesIndex struct {
|
|
dbClient *database.DB
|
|
}
|
|
|
|
func (mig *ReplaceCurrentSequencesIndex) Execute(ctx context.Context, _ eventstore.Event) error {
|
|
statements, err := readStatements(replaceCurrentSequencesIndex, "44", "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, stmt := range statements {
|
|
logging.WithFields("file", stmt.file, "migration", mig.String()).Info("execute statement")
|
|
if _, err := mig.dbClient.ExecContext(ctx, stmt.query); err != nil {
|
|
return fmt.Errorf("%s %s: %w", mig.String(), stmt.file, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mig *ReplaceCurrentSequencesIndex) String() string {
|
|
return "44_replace_current_sequences_index"
|
|
}
|