2020-05-26 14:46:16 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2020-06-25 06:01:13 +00:00
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
2020-12-02 07:50:59 +00:00
|
|
|
"time"
|
2020-05-26 14:46:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-07-07 14:53:54 +00:00
|
|
|
sequencesTable = "adminapi.current_sequences"
|
2020-05-26 14:46:16 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) saveCurrentSequence(viewName string, sequence uint64, eventTimeStamp time.Time) error {
|
|
|
|
return repository.SaveCurrentSequence(v.Db, sequencesTable, viewName, sequence, eventTimeStamp)
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 11:24:36 +00:00
|
|
|
func (v *View) latestSequence(viewName string) (*repository.CurrentSequence, error) {
|
2020-06-25 06:01:13 +00:00
|
|
|
return repository.LatestSequence(v.Db, sequencesTable, viewName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) AllCurrentSequences(db string) ([]*repository.CurrentSequence, error) {
|
|
|
|
return repository.AllCurrentSequences(v.Db, db+".current_sequences")
|
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) updateSpoolerRunSequence(viewName string) error {
|
|
|
|
currentSequence, err := repository.LatestSequence(v.Db, sequencesTable, viewName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if currentSequence.ViewName == "" {
|
|
|
|
currentSequence.ViewName = viewName
|
|
|
|
}
|
|
|
|
currentSequence.LastSuccessfulSpoolerRun = time.Now()
|
|
|
|
return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) GetCurrentSequence(db, viewName string) (*repository.CurrentSequence, error) {
|
|
|
|
sequenceTable := db + ".current_sequences"
|
|
|
|
fullView := db + "." + viewName
|
|
|
|
return repository.LatestSequence(v.Db, sequenceTable, fullView)
|
|
|
|
}
|
|
|
|
|
2020-06-25 06:01:13 +00:00
|
|
|
func (v *View) ClearView(db, viewName string) error {
|
|
|
|
truncateView := db + "." + viewName
|
|
|
|
sequenceTable := db + ".current_sequences"
|
|
|
|
return repository.ClearView(v.Db, truncateView, sequenceTable)
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|