graph/db: move graph disabled check to inside populateCache
What changed, and why it matters
This commit is a simple internal code cleanup. It moves a nil-check for an optional in-memory graph cache from the caller into the function that fills the cache. Behavior is unchanged: if the cache is disabled, the function returns immediately. There is no user-visible or security-relevant change.
No action required. Treat as a normal non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors ChannelGraph.Start() and populateCache() in graph/db/graph.go. Previously Start() checked if c.graphCache != nil before calling populateCache(). Now Start() always calls populateCache(), and populateCache() itself returns early if c.graphCache == nil. The comment noting that populateCache() should only be called when the cache is constructed was removed because the guard is now internal. This is a pure refactor with identical runtime behavior.
Changed components
graph/db/graph.goChannelGraph.Start()ChannelGraph.populateCache()Inspect captured patch +8 / −7
diff --git a/graph/db/graph.go b/graph/db/graph.go
index 3568986..eb84603 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -79,11 +79,8 @@ func (c *ChannelGraph) Start() error {
ctx := context.TODO()
- if c.graphCache != nil {
- if err := c.populateCache(ctx); err != nil {
- return fmt.Errorf("could not populate the graph "+
- "cache: %w", err)
- }
+ if err := c.populateCache(ctx); err != nil {
+ return fmt.Errorf("could not populate the graph cache: %w", err)
}
c.wg.Add(1)
@@ -165,9 +162,13 @@ func (c *ChannelGraph) handleTopologySubscriptions(ctx context.Context) {
}
// populateCache loads the entire channel graph into the in-memory graph cache.
-//
-// NOTE: This should only be called if the graphCache has been constructed.
func (c *ChannelGraph) populateCache(ctx context.Context) error {
+ if c.graphCache == nil {
+ log.Info("In-memory channel graph cache disabled")
+
+ return nil
+ }
+
startTime := time.Now()
log.Info("Populating in-memory channel graph, this might take a " +
"while...")
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.