support multiple mutations
All checks were successful
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m13s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m54s

This commit is contained in:
2025-10-13 19:51:27 +02:00
parent 91e398dcc3
commit 8e60cc2239
5 changed files with 33 additions and 26 deletions

View File

@@ -26,7 +26,7 @@ type DiskStorage[V any] struct {
type LogStorage[V any] interface {
LoadEvents(id uint64, grain Grain[V]) error
AppendEvent(id uint64, msg proto.Message) error
AppendEvent(id uint64, msg ...proto.Message) error
}
func NewDiskStorage[V any](path string, registry MutationRegistry) *DiskStorage[V] {
@@ -102,14 +102,16 @@ func (s *DiskStorage[V]) Close() {
close(s.done)
}
func (s *DiskStorage[V]) AppendEvent(id uint64, msg proto.Message) error {
func (s *DiskStorage[V]) AppendEvent(id uint64, msg ...proto.Message) error {
if s.queue != nil {
queue := make([]QueueEvent, 0)
data, found := s.queue.Load(id)
if found {
queue = data.([]QueueEvent)
}
queue = append(queue, QueueEvent{Message: msg})
for _, m := range msg {
queue = append(queue, QueueEvent{Message: m, TimeStamp: time.Now()})
}
s.queue.Store(id, queue)
return nil
} else {
@@ -120,8 +122,10 @@ func (s *DiskStorage[V]) AppendEvent(id uint64, msg proto.Message) error {
return err
}
defer fh.Close()
return s.Append(fh, msg, time.Now())
for _, m := range msg {
err = s.Append(fh, m, time.Now())
}
return err
}
}