fix(eventstore): improve pagination of handler filter (#6968)

* fix(setup): add filter_offset to `projections.current_states`

* fix(eventstore): allow offset in query

* fix(handler): offset for already processed events
This commit is contained in:
Silvan
2023-12-01 13:25:41 +01:00
committed by GitHub
parent e57076430b
commit e3d1ca4d58
20 changed files with 512 additions and 174 deletions

View File

@@ -19,6 +19,7 @@ type state struct {
aggregateType eventstore.AggregateType
aggregateID string
sequence uint64
offset uint16
}
var (
@@ -30,8 +31,6 @@ var (
updateStateStmt string
//go:embed state_lock.sql
lockStateStmt string
//go:embed state_set_last_run.sql
updateStateLastRunStmt string
errJustUpdated = errors.New("projection was just updated")
)
@@ -47,6 +46,7 @@ func (h *Handler) currentState(ctx context.Context, tx *sql.Tx, config *triggerC
sequence = new(sql.NullInt64)
timestamp = new(sql.NullTime)
position = new(sql.NullFloat64)
offset = new(sql.NullInt16)
)
stateQuery := currentStateStmt
@@ -61,6 +61,7 @@ func (h *Handler) currentState(ctx context.Context, tx *sql.Tx, config *triggerC
sequence,
timestamp,
position,
offset,
)
if errors.Is(err, sql.ErrNoRows) {
err = h.lockState(tx, currentState.instanceID)
@@ -75,6 +76,7 @@ func (h *Handler) currentState(ctx context.Context, tx *sql.Tx, config *triggerC
currentState.sequence = uint64(sequence.Int64)
currentState.eventTimestamp = timestamp.Time
currentState.position = position.Float64
currentState.offset = uint16(offset.Int16)
return currentState, nil
}
@@ -87,6 +89,7 @@ func (h *Handler) setState(tx *sql.Tx, updatedState *state) error {
updatedState.sequence,
updatedState.eventTimestamp,
updatedState.position,
updatedState.offset,
)
if err != nil {
h.log().WithError(err).Debug("unable to update state")
@@ -99,11 +102,6 @@ func (h *Handler) setState(tx *sql.Tx, updatedState *state) error {
return nil
}
func (h *Handler) updateLastUpdated(ctx context.Context, tx *sql.Tx, updatedState *state) {
_, err := tx.ExecContext(ctx, updateStateLastRunStmt, h.projection.Name(), updatedState.instanceID)
h.log().OnError(err).Debug("unable to update last updated")
}
func (h *Handler) lockState(tx *sql.Tx, instanceID string) error {
res, err := tx.Exec(lockStateStmt,
h.projection.Name(),