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

@@ -157,6 +157,20 @@ func (p *GrainLocalPool) Purge() {
}
}
// RefreshExpiry resets the expiry timestamp for a living grain to now + TTL.
// Called after successful mutations to implement a sliding inactivity window.
func (p *GrainLocalPool) RefreshExpiry(id CartId) {
p.mu.Lock()
defer p.mu.Unlock()
for i := range p.expiry {
g := p.expiry[i].Grain
if g != nil && g.Id == id {
p.expiry[i].Expires = time.Now().Add(p.Ttl)
break
}
}
}
// GetGrains returns a legacy view of grains (copy) for compatibility.
func (p *GrainLocalPool) GetGrains() map[CartId]*CartGrain {
p.mu.RLock()
@@ -225,7 +239,12 @@ func (p *GrainLocalPool) Apply(id CartId, mutation interface{}) (*CartGrain, err
if err != nil || grain == nil {
return nil, err
}
return grain.Apply(mutation, false)
result, applyErr := grain.Apply(mutation, false)
// Sliding TTL: refresh expiry on successful non-replay mutation (Apply always non-replay here)
if applyErr == nil && result != nil {
p.RefreshExpiry(id)
}
return result, applyErr
}
// Get returns current state (legacy wrapper).