diff --git a/commonspace/object/tree/objecttree/objecttree_test.go b/commonspace/object/tree/objecttree/objecttree_test.go index 0987d214..d65d15fc 100644 --- a/commonspace/object/tree/objecttree/objecttree_test.go +++ b/commonspace/object/tree/objecttree/objecttree_test.go @@ -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) diff --git a/commonspace/object/tree/objecttree/objecttreevalidator.go b/commonspace/object/tree/objecttree/objecttreevalidator.go index 2fbf5565..bb971ad7 100644 --- a/commonspace/object/tree/objecttree/objecttreevalidator.go +++ b/commonspace/object/tree/objecttree/objecttreevalidator.go @@ -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 }