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:
parent
58f333354e
commit
bc6638414c
2 changed files with 7 additions and 11 deletions
|
@ -702,7 +702,7 @@ func TestObjectTree(t *testing.T) {
|
|||
ctx.changeCreator.CreateRawWithData("8", aclList.Head().Id, "6", false, []byte("8"), "6"),
|
||||
}
|
||||
_, err := ctx.objTree.AddRawChanges(context.Background(), RawChangesPayload{
|
||||
NewHeads: []string{"6"},
|
||||
NewHeads: []string{"7", "8"},
|
||||
RawChanges: rawChanges,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -35,21 +35,18 @@ func (n *noOpTreeValidator) FilterChanges(aclList list.AclList, heads []string,
|
|||
if n.filterFunc == nil {
|
||||
return false, changes, snapshots, indexes
|
||||
}
|
||||
var existingHeadsCount int
|
||||
for idx, c := range changes {
|
||||
// only taking changes which we can read
|
||||
if n.filterFunc(c) {
|
||||
if slice.FindPos(heads, c.Id) != -1 {
|
||||
existingHeadsCount++
|
||||
}
|
||||
newIndexes = append(newIndexes, indexes[idx])
|
||||
filtered = append(filtered, c)
|
||||
if c.IsSnapshot {
|
||||
filteredSnapshots = append(filteredSnapshots, c)
|
||||
}
|
||||
} else {
|
||||
filteredHeads = true
|
||||
}
|
||||
}
|
||||
filteredHeads = existingHeadsCount != len(heads)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -90,21 +87,20 @@ func (v *objectTreeValidator) FilterChanges(aclList list.AclList, heads []string
|
|||
aclList.RLock()
|
||||
defer aclList.RUnlock()
|
||||
state := aclList.AclState()
|
||||
var existingHeadsCount int
|
||||
for idx, c := range changes {
|
||||
// only taking changes which we can read
|
||||
if keys, exists := state.Keys()[c.ReadKeyId]; exists && keys.ReadKey != nil {
|
||||
if slice.FindPos(heads, c.Id) != -1 {
|
||||
existingHeadsCount++
|
||||
}
|
||||
newIndexes = append(newIndexes, indexes[idx])
|
||||
filtered = append(filtered, c)
|
||||
if c.IsSnapshot {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue