1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 18:20:28 +09:00

Update storage

This commit is contained in:
mcrakhman 2025-01-20 19:08:24 +01:00
parent 4f00849cab
commit b89d252396
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B

View file

@ -208,16 +208,15 @@ func (s *storage) AddAll(ctx context.Context, changes []StorageChange, heads []s
if err != nil {
return fmt.Errorf("failed to create write tx: %w", err)
}
vals := make([]*anyenc.Value, 0, len(changes))
for _, ch := range changes {
ch.TreeId = s.id
newVal := newStorageChangeValue(ch, arena)
vals = append(vals, newVal)
}
err = s.changesColl.Insert(tx.Context(), vals...)
if err != nil {
tx.Rollback()
return nil
err = s.changesColl.Insert(tx.Context(), newVal)
arena.Reset()
if err != nil {
tx.Rollback()
return err
}
}
update := headstorage.HeadsUpdate{
Id: s.id,
@ -227,7 +226,7 @@ func (s *storage) AddAll(ctx context.Context, changes []StorageChange, heads []s
err = s.headStorage.UpdateEntryTx(tx.Context(), update)
if err != nil {
tx.Rollback()
return nil
return err
}
return tx.Commit()
}