From f4647af7b4305f9436dc5461c90ab7f3e02ce9da Mon Sep 17 00:00:00 2001 From: quobix Date: Sat, 13 Jan 2024 10:04:48 -0500 Subject: [PATCH] Added switch to resolver for preventing duplication. vacuum runs things multiple times. which is causing skew on references. Signed-off-by: quobix --- datamodel/low/v3/create_document.go | 4 ++- index/resolver.go | 47 ++++++++++++++++++----------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/datamodel/low/v3/create_document.go b/datamodel/low/v3/create_document.go index 688d36e6..b1d43751 100644 --- a/datamodel/low/v3/create_document.go +++ b/datamodel/low/v3/create_document.go @@ -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() diff --git a/index/resolver.go b/index/resolver.go index 56eadb1b..d1cc275c 100644 --- a/index/resolver.go +++ b/index/resolver.go @@ -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 @@ -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 @@ -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 } @@ -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 @@ -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 } @@ -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) + } } } } @@ -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) + } } } }