Build item policies without repeated accumulated copies
This commit is contained in:
@@ -960,7 +960,12 @@ func projectNestedCollectionPolicies(composed *composedDocument, scope acquisiti
|
||||
if composed == nil {
|
||||
return
|
||||
}
|
||||
baseOffsets := make(map[string]int)
|
||||
type itemPolicyProjection struct {
|
||||
destination Path
|
||||
policy collectionPolicy
|
||||
base int
|
||||
}
|
||||
projected := make(map[string]*itemPolicyProjection)
|
||||
var prefixLengths map[string]int
|
||||
for sourceIndex, contribution := range scope.contributions {
|
||||
if prefixLengths != nil && sourceIndex > 0 {
|
||||
@@ -983,17 +988,21 @@ func projectNestedCollectionPolicies(composed *composedDocument, scope acquisiti
|
||||
}
|
||||
itemIndex = prefixLengths[key]
|
||||
}
|
||||
base, initialized := baseOffsets[key]
|
||||
policy, _ := composed.collectionPolicies.at(contribution.destination)
|
||||
working, initialized := projected[key]
|
||||
if !initialized {
|
||||
base = len(policy.recordOrder)
|
||||
baseOffsets[key] = base
|
||||
// Read one owned copy per destination, then add each incoming
|
||||
// record without recopying earlier records and their scopes.
|
||||
policy, _ := composed.collectionPolicies.at(contribution.destination)
|
||||
working = &itemPolicyProjection{destination: contribution.destination, policy: policy, base: len(policy.recordOrder)}
|
||||
projected[key] = working
|
||||
}
|
||||
policy.setRecordPolicyAt(base+itemIndex, collectionRecordPolicy{
|
||||
working.policy.setRecordPolicyAt(working.base+itemIndex, collectionRecordPolicy{
|
||||
owner: newCollectionRecordPolicy().owner,
|
||||
scope: contribution.nested.collectionPolicies,
|
||||
})
|
||||
composed.collectionPolicies.set(contribution.destination, policy)
|
||||
}
|
||||
for _, working := range projected {
|
||||
composed.collectionPolicies.set(working.destination, working.policy)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user