Skip to content

Commit

Permalink
Added switch to resolver for preventing duplication.
Browse files Browse the repository at this point in the history
vacuum runs things multiple times. which is causing skew on references.

Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Jan 13, 2024
1 parent 2a1e4e5 commit f4647af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
4 changes: 3 additions & 1 deletion datamodel/low/v3/create_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func createDocument(info *datamodel.SpecInfo, config *datamodel.DocumentConfigur
}
done = time.Duration(time.Since(now).Milliseconds())
if config.Logger != nil {
config.Logger.Debug("circular check completed", "ms", done)
if !config.SkipCircularReferenceCheck {
config.Logger.Debug("circular check completed", "ms", done)
}
}
// extract errors
roloErrs := rolodex.GetCaughtErrors()
Expand Down
47 changes: 30 additions & 17 deletions index/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Resolver struct {
relativesSeen int
IgnorePoly bool
IgnoreArray bool
circChecked bool
}

// NewResolver will create a new resolver from a *index.SpecIndex
Expand Down Expand Up @@ -197,11 +198,13 @@ func (resolver *Resolver) Resolve() []*ResolvingError {
continue
}

resolver.resolvingErrors = append(resolver.resolvingErrors, &ResolvingError{
ErrorRef: fmt.Errorf("infinite circular reference detected: %s", circRef.Start.Definition),
Node: circRef.LoopPoint.Node,
Path: circRef.GenerateJourneyPath(),
})
if !resolver.circChecked {
resolver.resolvingErrors = append(resolver.resolvingErrors, &ResolvingError{
ErrorRef: fmt.Errorf("infinite circular reference detected: %s", circRef.Start.Definition),
Node: circRef.LoopPoint.Node,
Path: circRef.GenerateJourneyPath(),
})
}
}

return resolver.resolvingErrors
Expand All @@ -215,16 +218,18 @@ func (resolver *Resolver) CheckForCircularReferences() []*ResolvingError {
if !circRef.IsInfiniteLoop {
continue
}

resolver.resolvingErrors = append(resolver.resolvingErrors, &ResolvingError{
ErrorRef: fmt.Errorf("infinite circular reference detected: %s", circRef.Start.Name),
Node: circRef.LoopPoint.Node,
Path: circRef.GenerateJourneyPath(),
CircularReference: circRef,
})
if !resolver.circChecked {
resolver.resolvingErrors = append(resolver.resolvingErrors, &ResolvingError{
ErrorRef: fmt.Errorf("infinite circular reference detected: %s", circRef.Start.Name),
Node: circRef.LoopPoint.Node,
Path: circRef.GenerateJourneyPath(),
CircularReference: circRef,
})
}
}
// update our index with any circular refs we found.
resolver.specIndex.SetCircularReferences(resolver.circularReferences)
resolver.circChecked = true
return resolver.resolvingErrors
}

Expand Down Expand Up @@ -365,7 +370,9 @@ func (resolver *Resolver) VisitReference(ref *Reference, seen map[string]bool, j
if resolver.IgnoreArray && isArray {
resolver.ignoredArrayReferences = append(resolver.ignoredArrayReferences, circRef)
} else {
resolver.circularReferences = append(resolver.circularReferences, circRef)
if !resolver.circChecked {
resolver.circularReferences = append(resolver.circularReferences, circRef)
}
}
r.Seen = true
r.Circular = true
Expand Down Expand Up @@ -463,8 +470,10 @@ func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.No
LoopPoint: ref,
IsInfiniteLoop: true,
}
resolver.circularReferences = append(resolver.circularReferences, circRef)
ref.Circular = true
if !resolver.circChecked {
resolver.circularReferences = append(resolver.circularReferences, circRef)
ref.Circular = true
}
return nil
}

Expand Down Expand Up @@ -728,7 +737,9 @@ func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.No
if resolver.IgnorePoly {
resolver.ignoredPolyReferences = append(resolver.ignoredPolyReferences, circRef)
} else {
resolver.circularReferences = append(resolver.circularReferences, circRef)
if !resolver.circChecked {
resolver.circularReferences = append(resolver.circularReferences, circRef)
}
}
}
}
Expand Down Expand Up @@ -848,7 +859,9 @@ func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.No
if resolver.IgnorePoly {
resolver.ignoredPolyReferences = append(resolver.ignoredPolyReferences, circRef)
} else {
resolver.circularReferences = append(resolver.circularReferences, circRef)
if !resolver.circChecked {
resolver.circularReferences = append(resolver.circularReferences, circRef)
}
}
}
}
Expand Down

0 comments on commit f4647af

Please sign in to comment.