mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
feat: sequence and timestamp on searchrequests (#468)
* feat: reread events * feat: sequence and timestamo on search requests * feat: sequence and timestamo on search requests * fix: better naming * fix: log errors * fix: read sequence before search request
This commit is contained in:
@@ -5,15 +5,13 @@ import (
|
||||
"github.com/caos/zitadel/internal/view/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type actualSequece struct {
|
||||
ActualSequence uint64 `gorm:"column:current_sequence"`
|
||||
}
|
||||
|
||||
type CurrentSequence struct {
|
||||
ViewName string `gorm:"column:view_name;primary_key"`
|
||||
CurrentSequence uint64 `gorm:"column:current_sequence"`
|
||||
ViewName string `gorm:"column:view_name;primary_key"`
|
||||
CurrentSequence uint64 `gorm:"column:current_sequence"`
|
||||
CurrentTimestamp time.Time `gorm:"column:timestamp"`
|
||||
}
|
||||
|
||||
type SequenceSearchKey int32
|
||||
@@ -37,15 +35,16 @@ func (key sequenceSearchKey) ToColumnName() string {
|
||||
func CurrentSequenceToModel(sequence *CurrentSequence) *model.View {
|
||||
dbView := strings.Split(sequence.ViewName, ".")
|
||||
return &model.View{
|
||||
Database: dbView[0],
|
||||
ViewName: dbView[1],
|
||||
CurrentSequence: sequence.CurrentSequence,
|
||||
Database: dbView[0],
|
||||
ViewName: dbView[1],
|
||||
CurrentSequence: sequence.CurrentSequence,
|
||||
CurrentTimestamp: sequence.CurrentTimestamp,
|
||||
}
|
||||
}
|
||||
|
||||
func SaveCurrentSequence(db *gorm.DB, table, viewName string, sequence uint64) error {
|
||||
save := PrepareSave(table)
|
||||
err := save(db, &CurrentSequence{viewName, sequence})
|
||||
err := save(db, &CurrentSequence{viewName, sequence, time.Now()})
|
||||
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-5kOhP", "unable to updated processed sequence")
|
||||
@@ -53,19 +52,19 @@ func SaveCurrentSequence(db *gorm.DB, table, viewName string, sequence uint64) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func LatestSequence(db *gorm.DB, table, viewName string) (uint64, error) {
|
||||
sequence := new(actualSequece)
|
||||
func LatestSequence(db *gorm.DB, table, viewName string) (*CurrentSequence, error) {
|
||||
sequence := new(CurrentSequence)
|
||||
query := PrepareGetByKey(table, sequenceSearchKey(SequenceSearchKeyViewName), viewName)
|
||||
err := query(db, sequence)
|
||||
|
||||
if err == nil {
|
||||
return sequence.ActualSequence, nil
|
||||
return sequence, nil
|
||||
}
|
||||
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return 0, nil
|
||||
return sequence, nil
|
||||
}
|
||||
return 0, caos_errs.ThrowInternalf(err, "VIEW-9LyCB", "unable to get latest sequence of %s", viewName)
|
||||
return nil, caos_errs.ThrowInternalf(err, "VIEW-9LyCB", "unable to get latest sequence of %s", viewName)
|
||||
}
|
||||
|
||||
func AllCurrentSequences(db *gorm.DB, table string) ([]*CurrentSequence, error) {
|
||||
|
Reference in New Issue
Block a user