some strange storage stuff
Some checks failed
Build and Publish / Metadata (push) Successful in 4s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 48s
Build and Publish / BuildAndDeployArm64 (push) Failing after 26m40s

This commit is contained in:
matst80
2025-10-10 19:31:06 +00:00
parent fb111ebf97
commit 7814f33a06
5 changed files with 339 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"sync"
"time"
messages "git.tornberg.me/go-cart-actor/proto"
)
@@ -89,6 +90,7 @@ type CartGrain struct {
mu sync.RWMutex
lastItemId int
lastDeliveryId int
lastChange int64 // unix seconds of last successful mutation (replay sets from event ts)
Id CartId `json:"id"`
Items []*CartItem `json:"items"`
TotalPrice int64 `json:"totalPrice"`
@@ -112,8 +114,7 @@ func (c *CartGrain) GetId() CartId {
}
func (c *CartGrain) GetLastChange() int64 {
// Legacy event log removed; return 0 to indicate no persisted mutation history.
return 0
return c.lastChange
}
func (c *CartGrain) GetCurrentState() (*CartGrain, error) {
@@ -269,6 +270,13 @@ func (c *CartGrain) Apply(content interface{}, isReplay bool) (*CartGrain, error
}
return nil, err
}
// Sliding TTL: update lastChange only for non-replay successful mutations.
if updated != nil && !isReplay {
c.lastChange = time.Now().Unix()
_ = AppendCartEvent(c.Id, content)
}
return updated, nil
}