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

Copy data in load iterator

This commit is contained in:
mcrakhman 2024-11-25 16:53:13 +01:00
parent 825878ae4d
commit 305205a8ba
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
4 changed files with 13 additions and 8 deletions

View file

@ -81,8 +81,10 @@ func (l *loadIterator) NextBatch(maxSize int) (batch IteratorBatch, err error) {
}
curSize += rawEntry.size
cp := make([]byte, 0, len(c.RawChange))
cp = append(cp, c.RawChange...)
batch.Batch = append(batch.Batch, &treechangeproto.RawTreeChangeWithId{
RawChange: c.RawChange,
RawChange: cp,
Id: c.Id,
})
batch.Heads = slice.DiscardFromSlice(batch.Heads, func(s string) bool {

View file

@ -786,7 +786,8 @@ func TestObjectTree(t *testing.T) {
for _, ch := range rawChanges {
raw, err := treeStorage.Get(context.Background(), ch.Id)
assert.NoError(t, err, "storage should have all the changes")
assert.Equal(t, ch, raw, "the changes in the storage should be the same")
assert.Equal(t, ch.Id, raw.RawTreeChangeWithId().Id, "the changes in the storage should be the same")
assert.Equal(t, ch.RawChange, raw.RawTreeChangeWithId().RawChange, "the changes in the storage should be the same")
}
})
@ -912,7 +913,8 @@ func TestObjectTree(t *testing.T) {
for _, ch := range rawChanges {
raw, err := treeStorage.Get(context.Background(), ch.Id)
assert.NoError(t, err, "storage should have all the changes")
assert.Equal(t, ch, raw, "the changes in the storage should be the same")
assert.Equal(t, ch.Id, raw.RawTreeChangeWithId().Id, "the changes in the storage should be the same")
assert.Equal(t, ch.RawChange, raw.RawTreeChangeWithId().RawChange, "the changes in the storage should be the same")
}
})
@ -995,7 +997,8 @@ func TestObjectTree(t *testing.T) {
for _, ch := range rawChanges {
raw, err := treeStorage.Get(context.Background(), ch.Id)
assert.NoError(t, err, "storage should have all the changes")
assert.Equal(t, ch, raw, "the changes in the storage should be the same")
assert.Equal(t, ch.Id, raw.RawTreeChangeWithId().Id, "the changes in the storage should be the same")
assert.Equal(t, ch.RawChange, raw.RawTreeChangeWithId().RawChange, "the changes in the storage should be the same")
treeCh, err := objTree.GetChange(ch.Id)
if ch.Id == "3" || ch.Id == "4" {
require.NoError(t, err)
@ -1071,7 +1074,7 @@ func TestObjectTree(t *testing.T) {
treeCtx := prepareTreeContext(t, aclList)
changeCreator := treeCtx.changeCreator
objTree := treeCtx.objTree
store := treeCtx.treeStorage.(testStorage)
store := treeCtx.treeStorage.(*testStorage)
store.errAdd = fmt.Errorf("error saving")
rawChanges := []*treechangeproto.RawTreeChangeWithId{

View file

@ -278,7 +278,7 @@ func (s *storage) Get(ctx context.Context, id string) (StorageChange, error) {
if err != nil {
return StorageChange{}, err
}
ch, err := s.changeFromDoc(s.id, doc)
ch, err := s.changeFromDoc(id, doc)
if err != nil {
return StorageChange{}, err
}

View file

@ -81,7 +81,7 @@ type testStorage struct {
errAdd error
}
func (t testStorage) AddAll(ctx context.Context, changes []StorageChange, heads []string, commonSnapshot string) error {
func (t *testStorage) AddAll(ctx context.Context, changes []StorageChange, heads []string, commonSnapshot string) error {
if t.errAdd != nil {
return t.errAdd
}
@ -166,7 +166,7 @@ func (c *MockChangeCreator) CreateNewTreeStorage(t *testing.T, treeId, aclHeadId
}
storage, err := createStorage(context.Background(), root, c.store)
require.NoError(t, err)
return testStorage{
return &testStorage{
Storage: storage,
}
}