From 3a338cdb443376f41a89d5d8f5931be743bd13f8 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Thu, 29 Jun 2023 14:28:27 +0200 Subject: [PATCH] push 6 in 6 milestones --- internal/eventstore/handler/crdb/statement.go | 12 ++++- .../eventstore/handler/handler_projection.go | 6 +-- internal/query/projection/milestones.go | 44 +++++++++++-------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/internal/eventstore/handler/crdb/statement.go b/internal/eventstore/handler/crdb/statement.go index ebf5455863..fd042c61bb 100644 --- a/internal/eventstore/handler/crdb/statement.go +++ b/internal/eventstore/handler/crdb/statement.go @@ -290,7 +290,17 @@ func NewIsNullCond(column string) handler.Condition { return handler.Condition{ Name: column, ParameterOpt: func(string) string { - return fmt.Sprintf("%s IS NULL", column) + return " IS NULL" + }, + } +} + +func NewNotEqualCond(column, value string) handler.Condition { + return handler.Condition{ + Name: column, + Value: value, + ParameterOpt: func(param string) string { + return fmt.Sprintf(" != %s", param) }, } } diff --git a/internal/eventstore/handler/handler_projection.go b/internal/eventstore/handler/handler_projection.go index d7aed5ef3b..c0e6728caa 100644 --- a/internal/eventstore/handler/handler_projection.go +++ b/internal/eventstore/handler/handler_projection.go @@ -100,13 +100,13 @@ func NewProjectionHandler( reduceScheduledPseudoEvent: reduceScheduledPseudoEvent, } - go func() { + go func(subscribe bool) { <-initialized - if !h.reduceScheduledPseudoEvent { + if subscribe { go h.subscribe(ctx) } go h.schedule(ctx) - }() + }(!h.reduceScheduledPseudoEvent) return h } diff --git a/internal/query/projection/milestones.go b/internal/query/projection/milestones.go index 22a4e39bb8..19f40de250 100644 --- a/internal/query/projection/milestones.go +++ b/internal/query/projection/milestones.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "github.com/zitadel/zitadel/internal/repository/milestone" @@ -127,14 +128,22 @@ func (p *milestoneProjection) reducePushed(event eventstore.Event) (*handler.Sta if !ok { return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-XJGXK", "reduce.wrong.event.type %s", milestone.PushedEventType) } - return crdb.NewUpdateStatement( + if e.MilestoneType != milestone.InstanceDeleted { + return crdb.NewUpdateStatement( + event, + []handler.Column{ + handler.NewCol(MilestoneColumnPushedDate, event.CreationDate()), + }, + []handler.Condition{ + handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID), + handler.NewCond(MilestoneColumnType, e.MilestoneType), + }, + ), nil + } + return crdb.NewDeleteStatement( event, - []handler.Column{ - handler.NewCol(MilestoneColumnPushedDate, event.CreationDate()), - }, []handler.Condition{ handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID), - handler.NewCond(MilestoneColumnType, e.MilestoneType), }, ), nil } @@ -194,7 +203,6 @@ func (p *milestoneProjection) reduceProjectAdded(event eventstore.Event) (*handl } func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*handler.Statement, error) { - printEvent(event) e, ok := event.(*user.UserTokenAddedEvent) if !ok { return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-3xhJ7", "reduce.wrong.event.type %s", user.UserTokenAddedType) @@ -211,19 +219,17 @@ func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*han crdb.NewIsNullCond(MilestoneColumnReachedDate), }, ), - /* crdb.AddUpdateStatement( - []handler.Column{ - handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()), - }, - []handler.Condition{ - handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID), - handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication), - crdb.NewExpressionCond(func(param string) (clause string, needsParam bool) { - return fmt.Sprintf("%s") - }), - crdb.NewIsNullCond(MilestoneColumnReachedDate), - }, - ),*/ + crdb.AddUpdateStatement( + []handler.Column{ + handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()), + }, + []handler.Condition{ + handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID), + handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication), + crdb.NewNotEqualCond(MilestoneColumnIgnoredProject, strings.Split(e.ApplicationID, "@")[0]), + crdb.NewIsNullCond(MilestoneColumnReachedDate), + }, + ), ), nil }