Localize history selection to affected paths
This commit is contained in:
@@ -69,7 +69,7 @@ type historyModel struct {
|
||||
shapesByPointer map[string][]Path
|
||||
shapeOrder []Path
|
||||
observationsByPointer map[string][]int
|
||||
reportedPathIndex pathPrefixIndex
|
||||
affectedPathIndex pathPrefixIndex
|
||||
documentLookup *documentLookup
|
||||
|
||||
frozen bool
|
||||
@@ -127,14 +127,14 @@ func (builder *historyBuilder) addObservation(observation historyObservation) in
|
||||
builder.model.observations = append(builder.model.observations, observation)
|
||||
builder.addShape(observation.path)
|
||||
switch observation.role {
|
||||
case historyRoleDefinition, historyRoleContribution, historyRoleCompositeDefinition, historyRoleCheckpoint:
|
||||
case historyRoleDefinition, historyRoleContribution, historyRoleCompositeDefinition, historyRoleCheckpoint, historyRoleOperation, historyRoleControl:
|
||||
pointer := observation.path.String()
|
||||
builder.model.observationsByPointer[pointer] = append(builder.model.observationsByPointer[pointer], observationID)
|
||||
if observation.role == historyRoleContribution {
|
||||
builder.model.reportedPathIndex.insert(pointer, observationID)
|
||||
if observation.role == historyRoleContribution || observation.role == historyRoleOperation || observation.role == historyRoleControl {
|
||||
// Index the concrete affected path, not the common reported ancestor.
|
||||
// A leaf query must not enumerate every sibling fact of one operation.
|
||||
builder.model.affectedPathIndex.insert(pointer, observationID)
|
||||
}
|
||||
case historyRoleOperation, historyRoleControl:
|
||||
builder.model.reportedPathIndex.insert(observation.reportedPath.String(), observationID)
|
||||
}
|
||||
return observationID
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ func (model *historyModel) selectHistory(path Path) []historySelection {
|
||||
for _, observationID := range model.observationsByPointer[path.String()] {
|
||||
candidateSet[observationID] = struct{}{}
|
||||
}
|
||||
model.reportedPathIndex.visitAncestors(path.String(), func(observationID int) {
|
||||
candidateSet[observationID] = struct{}{}
|
||||
})
|
||||
model.reportedPathIndex.visitDescendants(path.String(), func(observationID int) {
|
||||
// Producers register all affected before/after paths. Exact facts cover
|
||||
// ancestor replacements; descendants cover operations within an enclosing
|
||||
// query. Logical operations are still deduplicated by payload below.
|
||||
model.affectedPathIndex.visitDescendants(path.String(), func(observationID int) {
|
||||
candidateSet[observationID] = struct{}{}
|
||||
})
|
||||
candidates := make([]int, 0, len(candidateSet))
|
||||
|
||||
@@ -192,26 +192,25 @@ func sourceApplicationOrigin(application historyApplication, node *document.Node
|
||||
}
|
||||
|
||||
func sourceOriginRepresentedByOperation(model *historyModel, path Path, origin Origin) bool {
|
||||
represented := false
|
||||
model.reportedPathIndex.visitAncestors(path.String(), func(observationID int) {
|
||||
for _, observationID := range model.observationsByPointer[path.String()] {
|
||||
observation := model.observations[observationID]
|
||||
if observation.phase != historyPhaseSources || observation.role != historyRoleOperation {
|
||||
return
|
||||
continue
|
||||
}
|
||||
if !observation.afterPresent || !sameConcreteHistoryPath(path, observation.path) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
operationOrigin, ok := model.resolveAttribution(observation.attributionRef)
|
||||
if !ok {
|
||||
return
|
||||
continue
|
||||
}
|
||||
if originRepresentedByChange(path, origin, Change{
|
||||
Path: observation.reportedPath, Origin: operationOrigin.origin,
|
||||
}) {
|
||||
represented = true
|
||||
return true
|
||||
}
|
||||
})
|
||||
return represented
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func originRepresentedByChange(path Path, origin Origin, change Change) bool {
|
||||
|
||||
Reference in New Issue
Block a user