Prepare coalesced resolution replay
This commit is contained in:
@@ -179,28 +179,50 @@ func mergeHistoryAtPath(root **document.Node, path Path, incoming *document.Node
|
||||
// intent into that event rather than replay a child assignment a second time.
|
||||
func coalescedResolutionSnapshots(snapshots []resolutionSnapshot) []resolutionSnapshot {
|
||||
groups := make([]resolutionSnapshot, 0, len(snapshots))
|
||||
reasons := make([]map[string]struct{}, 0, len(snapshots))
|
||||
dependencies := make([]map[string]struct{}, 0, len(snapshots))
|
||||
var coverage pathPrefixIndex
|
||||
for _, snapshot := range snapshots {
|
||||
merged := false
|
||||
for i := range groups {
|
||||
if !pathContains(groups[i].change.Path, snapshot.change.Path) {
|
||||
continue
|
||||
pointer := snapshot.change.Path.String()
|
||||
groupIndex := -1
|
||||
coverage.visitAncestors(pointer, func(id int) {
|
||||
if groupIndex < 0 || id < groupIndex {
|
||||
groupIndex = id
|
||||
}
|
||||
})
|
||||
if groupIndex >= 0 {
|
||||
group := &groups[groupIndex]
|
||||
for _, reason := range snapshot.change.Reasons {
|
||||
groups[i].change.Reasons = appendUniqueString(groups[i].change.Reasons, reason)
|
||||
if _, found := reasons[groupIndex][reason]; !found {
|
||||
reasons[groupIndex][reason] = struct{}{}
|
||||
group.change.Reasons = append(group.change.Reasons, reason)
|
||||
}
|
||||
}
|
||||
for _, dependency := range snapshot.change.Dependencies {
|
||||
groups[i].change.Dependencies = appendUniquePath(groups[i].change.Dependencies, dependency)
|
||||
dependencyPointer := dependency.String()
|
||||
if _, found := dependencies[groupIndex][dependencyPointer]; !found {
|
||||
dependencies[groupIndex][dependencyPointer] = struct{}{}
|
||||
group.change.Dependencies = append(group.change.Dependencies, dependency.clone())
|
||||
}
|
||||
}
|
||||
if snapshot.change.Origin.Operation == ChangeNormalization {
|
||||
groups[i].change.Origin.Operation = ChangeNormalization
|
||||
group.change.Origin.Operation = ChangeNormalization
|
||||
}
|
||||
merged = true
|
||||
break
|
||||
continue
|
||||
}
|
||||
if !merged {
|
||||
snapshot.change = cloneChange(snapshot.change)
|
||||
groups = append(groups, snapshot)
|
||||
snapshot.change = cloneChange(snapshot.change)
|
||||
groups = append(groups, snapshot)
|
||||
reasonSet := make(map[string]struct{}, len(snapshot.change.Reasons))
|
||||
for _, reason := range snapshot.change.Reasons {
|
||||
reasonSet[reason] = struct{}{}
|
||||
}
|
||||
reasons = append(reasons, reasonSet)
|
||||
dependencySet := make(map[string]struct{}, len(snapshot.change.Dependencies))
|
||||
for _, dependency := range snapshot.change.Dependencies {
|
||||
dependencySet[dependency.String()] = struct{}{}
|
||||
}
|
||||
dependencies = append(dependencies, dependencySet)
|
||||
coverage.insert(pointer, len(groups)-1)
|
||||
}
|
||||
return groups
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user