some strange storage stuff
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user