Complete historical inventory and query services
This commit is contained in:
@@ -18,6 +18,12 @@ type historySelection struct {
|
||||
previous []Origin
|
||||
}
|
||||
|
||||
type historySensitivityCandidate struct {
|
||||
path Path
|
||||
sensitive bool
|
||||
dependencies []Path
|
||||
}
|
||||
|
||||
func (model *historyModel) selectHistory(path Path) []historySelection {
|
||||
if model == nil || !path.valid() || !model.hasObservedShape(path) {
|
||||
return nil
|
||||
@@ -119,7 +125,7 @@ func (model *historyModel) observedPaths() []Path {
|
||||
|
||||
func (model *historyModel) historicalPaths() []Path {
|
||||
if model == nil {
|
||||
return nil
|
||||
return []Path{}
|
||||
}
|
||||
pointers := make([]string, 0, len(model.shapesByPointer))
|
||||
for pointer := range model.shapesByPointer {
|
||||
@@ -136,6 +142,39 @@ func (model *historyModel) historicalPaths() []Path {
|
||||
return paths
|
||||
}
|
||||
|
||||
func (model *historyModel) latestHistoricalLocation(path Path) (Location, bool) {
|
||||
selections := model.selectHistory(path)
|
||||
for selectionIndex := len(selections) - 1; selectionIndex >= 0; selectionIndex-- {
|
||||
selection := selections[selectionIndex]
|
||||
if selection.hasAttribution {
|
||||
if location, found := latestOriginDocumentLocation(selection.attribution.origin); found {
|
||||
return Location{SourceID: location.SourceID, Line: location.Line, Column: location.Column}, true
|
||||
}
|
||||
}
|
||||
for previousIndex := len(selection.previous) - 1; previousIndex >= 0; previousIndex-- {
|
||||
if location, found := latestOriginDocumentLocation(selection.previous[previousIndex]); found {
|
||||
return Location{SourceID: location.SourceID, Line: location.Line, Column: location.Column}, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return Location{}, false
|
||||
}
|
||||
|
||||
func (model *historyModel) sensitivityCandidates() []historySensitivityCandidate {
|
||||
if model == nil {
|
||||
return nil
|
||||
}
|
||||
candidates := make([]historySensitivityCandidate, 0, len(model.observations))
|
||||
for _, observation := range model.observations {
|
||||
candidate := historySensitivityCandidate{path: observation.path.clone(), sensitive: observation.sensitive}
|
||||
if attribution, found := model.resolveAttribution(observation.attributionRef); found {
|
||||
candidate.dependencies = attribution.dependencies
|
||||
}
|
||||
candidates = append(candidates, candidate)
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
|
||||
func (model *historyModel) resolveAttribution(ref historyAttributionRef) (historyAttribution, bool) {
|
||||
if model == nil || ref < 0 || int(ref) >= len(model.attributions) {
|
||||
return historyAttribution{}, false
|
||||
|
||||
Reference in New Issue
Block a user