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:
Fabi
2020-07-15 13:24:36 +02:00
committed by GitHub
parent 87155f8c9e
commit 423b86a03b
102 changed files with 7389 additions and 6302 deletions

View File

@@ -1,7 +1,12 @@
package model
import (
"time"
)
type View struct {
Database string
ViewName string
CurrentSequence uint64
Database string
ViewName string
CurrentSequence uint64
CurrentTimestamp time.Time
}

View File

@@ -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) {