From 7eb000fd1777fd169655a9fe20a3b26acf05fb99 Mon Sep 17 00:00:00 2001 From: matst80 Date: Mon, 20 Oct 2025 21:09:45 +0200 Subject: [PATCH] only after mutations --- cmd/cart/main.go | 24 +++++++++++++----------- pkg/actor/mutation_registry.go | 10 ++++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cmd/cart/main.go b/cmd/cart/main.go index 6c3a1e7..0e48304 100644 --- a/cmd/cart/main.go +++ b/cmd/cart/main.go @@ -117,17 +117,19 @@ func main() { promotionService := promotions.NewPromotionService(nil) reg := cart.NewCartMultationRegistry() - reg.RegisterProcessor(actor.NewMutationProcessor(func(g *cart.CartGrain) error { - ctx := promotions.NewContextFromCart(g) - _, actions := promotionService.EvaluateAll(promotionData.State.Promotions, ctx) - for _, action := range actions { - log.Printf("apply: %V", action) - } - return nil - }), actor.NewMutationProcessor(func(g *cart.CartGrain) error { - g.UpdateTotals() - return nil - })) + reg.RegisterProcessor( + actor.NewMutationProcessor(func(g *cart.CartGrain) error { + ctx := promotions.NewContextFromCart(g) + _, actions := promotionService.EvaluateAll(promotionData.State.Promotions, ctx) + for _, action := range actions { + log.Printf("apply: %V", action) + } + return nil + }), + actor.NewMutationProcessor(func(g *cart.CartGrain) error { + g.UpdateTotals() + return nil + })) diskStorage := actor.NewDiskStorage[cart.CartGrain]("data", reg) poolConfig := actor.GrainPoolConfig[cart.CartGrain]{ MutationRegistry: reg, diff --git a/pkg/actor/mutation_registry.go b/pkg/actor/mutation_registry.go index ca7d774..b76e693 100644 --- a/pkg/actor/mutation_registry.go +++ b/pkg/actor/mutation_registry.go @@ -225,10 +225,12 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) ([]ApplyR results = append(results, ApplyResult{Error: err, Type: rt.Name(), Mutation: m}) } - for _, processor := range r.processors { - err := processor.Process(grain) - if err != nil { - return results, err + if len(results) > 0 { + for _, processor := range r.processors { + err := processor.Process(grain) + if err != nil { + return results, err + } } } return results, nil