Avoid repeated prefix scans when projecting item policies
This commit is contained in:
@@ -195,6 +195,40 @@ func TestNestedItemPolicyProjectionUsesStableOutputIndexes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestItemPolicyProjectionCountsContributionsWithoutLocalPolicy(t *testing.T) {
|
||||
t.Parallel()
|
||||
items := Keys("items")
|
||||
for _, assignments := range []map[int]int{nil, {1: 2, 3: 4}, {1: 2}, {3: 4}} {
|
||||
t.Run(fmt.Sprint(assignments), func(t *testing.T) {
|
||||
local := collectionPolicyScope{}
|
||||
local.set(Keys("steps"), collectionPolicy{identityFields: []string{"name"}, identityPresent: true})
|
||||
scope := acquisitionScope{contributions: []acquiredContribution{
|
||||
{document: parseItemPolicyDocument(t, "inline", "items: [{id: inline-a}, {id: inline-b}]\n")},
|
||||
{document: parseItemPolicyDocument(t, "first", "items: [{id: first}]\n"), destination: items, nested: &composedDocument{collectionPolicies: local}},
|
||||
{document: parseItemPolicyDocument(t, "gap", "items: [{id: gap}]\n"), destination: items},
|
||||
{document: parseItemPolicyDocument(t, "second", "items: [{id: second}]\n"), destination: items, nested: &composedDocument{collectionPolicies: local}},
|
||||
}}
|
||||
ranges := make(map[sequenceRangeKey]sequenceRange)
|
||||
for sourceIndex, output := range assignments {
|
||||
ranges[sequenceRangeKey{sourceIndex: sourceIndex, path: items.String()}] = sequenceRange{start: output, end: output + 1}
|
||||
}
|
||||
composed := &composedDocument{}
|
||||
projectNestedCollectionPolicies(composed, scope, ranges)
|
||||
policy, _ := composed.collectionPolicies.at(items)
|
||||
if len(policy.recordOrder) != 5 {
|
||||
t.Fatalf("record policies = %d, want 5 positions", len(policy.recordOrder))
|
||||
}
|
||||
for index := range 5 {
|
||||
record, _ := policy.recordPolicyAt(index)
|
||||
_, found := record.scope.at(Keys("steps"))
|
||||
if found != (index == 2 || index == 4) {
|
||||
t.Errorf("local policy at item %d = %t", index, found)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverlaySequenceTransfersIncomingItemPolicyOwnership(t *testing.T) {
|
||||
path := Keys("records")
|
||||
registered := mustCompileSequenceIdentityPolicy(t, []sequenceIdentityRegistration{{selector: sequenceIdentitySelector{literalSequenceSelector("records")}, identityFields: []string{"id"}}})
|
||||
|
||||
Reference in New Issue
Block a user