1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Change filtering

This commit is contained in:
mcrakhman 2024-02-15 17:45:27 +01:00
parent 58f333354e
commit bc6638414c
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
2 changed files with 7 additions and 11 deletions

View file

@ -702,7 +702,7 @@ func TestObjectTree(t *testing.T) {
ctx.changeCreator.CreateRawWithData("8", aclList.Head().Id, "6", false, []byte("8"), "6"), ctx.changeCreator.CreateRawWithData("8", aclList.Head().Id, "6", false, []byte("8"), "6"),
} }
_, err := ctx.objTree.AddRawChanges(context.Background(), RawChangesPayload{ _, err := ctx.objTree.AddRawChanges(context.Background(), RawChangesPayload{
NewHeads: []string{"6"}, NewHeads: []string{"7", "8"},
RawChanges: rawChanges, RawChanges: rawChanges,
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -35,21 +35,18 @@ func (n *noOpTreeValidator) FilterChanges(aclList list.AclList, heads []string,
if n.filterFunc == nil { if n.filterFunc == nil {
return false, changes, snapshots, indexes return false, changes, snapshots, indexes
} }
var existingHeadsCount int
for idx, c := range changes { for idx, c := range changes {
// only taking changes which we can read // only taking changes which we can read
if n.filterFunc(c) { if n.filterFunc(c) {
if slice.FindPos(heads, c.Id) != -1 {
existingHeadsCount++
}
newIndexes = append(newIndexes, indexes[idx]) newIndexes = append(newIndexes, indexes[idx])
filtered = append(filtered, c) filtered = append(filtered, c)
if c.IsSnapshot { if c.IsSnapshot {
filteredSnapshots = append(filteredSnapshots, c) filteredSnapshots = append(filteredSnapshots, c)
} }
} else {
filteredHeads = true
} }
} }
filteredHeads = existingHeadsCount != len(heads)
return return
} }
@ -90,21 +87,20 @@ func (v *objectTreeValidator) FilterChanges(aclList list.AclList, heads []string
aclList.RLock() aclList.RLock()
defer aclList.RUnlock() defer aclList.RUnlock()
state := aclList.AclState() state := aclList.AclState()
var existingHeadsCount int
for idx, c := range changes { for idx, c := range changes {
// only taking changes which we can read // only taking changes which we can read
if keys, exists := state.Keys()[c.ReadKeyId]; exists && keys.ReadKey != nil { if keys, exists := state.Keys()[c.ReadKeyId]; exists && keys.ReadKey != nil {
if slice.FindPos(heads, c.Id) != -1 {
existingHeadsCount++
}
newIndexes = append(newIndexes, indexes[idx]) newIndexes = append(newIndexes, indexes[idx])
filtered = append(filtered, c) filtered = append(filtered, c)
if c.IsSnapshot { if c.IsSnapshot {
filteredSnapshots = append(filteredSnapshots, c) filteredSnapshots = append(filteredSnapshots, c)
} }
} else {
// if we filtered at least one change this can be the change between heads and other changes
// thus we cannot use heads
filteredHeads = true
} }
} }
filteredHeads = existingHeadsCount != len(heads)
return return
} }