mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
458a383de2
* fix: use current sequence for refetching of events * fix: use client ids
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package view
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
"github.com/zitadel/zitadel/internal/view/repository"
|
|
)
|
|
|
|
const (
|
|
sequencesTable = "adminapi.current_sequences"
|
|
)
|
|
|
|
func (v *View) saveCurrentSequence(viewName string, event *models.Event) error {
|
|
return repository.SaveCurrentSequence(v.Db, sequencesTable, viewName, event.InstanceID, event.Sequence, event.CreationDate)
|
|
}
|
|
|
|
func (v *View) latestSequence(ctx context.Context, viewName, instanceID string) (*repository.CurrentSequence, error) {
|
|
return repository.LatestSequence(v.Db, v.TimeTravel(ctx, sequencesTable), viewName, instanceID)
|
|
}
|
|
|
|
func (v *View) latestSequences(ctx context.Context, viewName string, instanceIDs []string) ([]*repository.CurrentSequence, error) {
|
|
return repository.LatestSequences(v.Db, v.TimeTravel(ctx, sequencesTable), viewName, instanceIDs)
|
|
}
|
|
|
|
func (v *View) AllCurrentSequences(db, instanceID string) ([]*repository.CurrentSequence, error) {
|
|
return repository.AllCurrentSequences(v.Db, db+".current_sequences", instanceID)
|
|
}
|
|
|
|
func (v *View) updateSpoolerRunSequence(viewName string, instanceIDs []string) error {
|
|
currentSequences, err := repository.LatestSequences(v.Db, sequencesTable, viewName, instanceIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, currentSequence := range currentSequences {
|
|
if currentSequence.ViewName == "" {
|
|
currentSequence.ViewName = viewName
|
|
}
|
|
currentSequence.LastSuccessfulSpoolerRun = time.Now()
|
|
}
|
|
return repository.UpdateCurrentSequences(v.Db, sequencesTable, currentSequences)
|
|
}
|
|
|
|
func (v *View) ClearView(db, viewName string) error {
|
|
truncateView := db + "." + viewName
|
|
sequenceTable := db + ".current_sequences"
|
|
return repository.ClearView(v.Db, truncateView, sequenceTable)
|
|
}
|