mirror of
https://github.com/zitadel/zitadel.git
synced 2025-10-17 15:43:03 +00:00
fix: handle multiple statements for a single event in projections (#2313)
* fix: handle multiple statements for a single event in projections * export func type * fix test * Update internal/eventstore/handler/crdb/statement.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/eventstore/handler/crdb/statement.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * change to pointers * add error test case Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
@@ -18,11 +18,11 @@ type ProjectionHandlerConfig struct {
|
||||
}
|
||||
|
||||
//Update updates the projection with the given statements
|
||||
type Update func(context.Context, []Statement, Reduce) (unexecutedStmts []Statement, err error)
|
||||
type Update func(context.Context, []*Statement, Reduce) (unexecutedStmts []*Statement, err error)
|
||||
|
||||
//Reduce reduces the given event to a statement
|
||||
//which is used to update the projection
|
||||
type Reduce func(eventstore.EventReader) ([]Statement, error)
|
||||
type Reduce func(eventstore.EventReader) (*Statement, error)
|
||||
|
||||
//Lock is used for mutex handling if needed on the projection
|
||||
type Lock func(context.Context, time.Duration) <-chan error
|
||||
@@ -46,7 +46,7 @@ type ProjectionHandler struct {
|
||||
ProjectionName string
|
||||
|
||||
lockMu sync.Mutex
|
||||
stmts []Statement
|
||||
stmts []*Statement
|
||||
}
|
||||
|
||||
func NewProjectionHandler(config ProjectionHandlerConfig) *ProjectionHandler {
|
||||
@@ -156,7 +156,7 @@ func (h *ProjectionHandler) processEvent(
|
||||
event eventstore.EventReader,
|
||||
reduce Reduce,
|
||||
) error {
|
||||
stmts, err := reduce(event)
|
||||
stmt, err := reduce(event)
|
||||
if err != nil {
|
||||
logging.Log("EVENT-PTr4j").WithError(err).Warn("unable to process event")
|
||||
return err
|
||||
@@ -165,7 +165,7 @@ func (h *ProjectionHandler) processEvent(
|
||||
h.lockMu.Lock()
|
||||
defer h.lockMu.Unlock()
|
||||
|
||||
h.stmts = append(h.stmts, stmts...)
|
||||
h.stmts = append(h.stmts, stmt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user