channeldb: speed up graph cache loading

Use the optimized ForEachChannel method to reduce the graph cache
loading time.
This commit is contained in:
Joost Jager
2021-12-23 10:27:19 +01:00
parent 2e2229a2e7
commit 352008a0c2
3 changed files with 110 additions and 10 deletions

View File

@@ -216,15 +216,29 @@ func NewChannelGraph(db kvdb.Backend, rejectCacheSize, chanCacheSize int,
startTime := time.Now()
log.Debugf("Populating in-memory channel graph, this might " +
"take a while...")
err := g.ForEachNodeCacheable(
func(tx kvdb.RTx, node GraphCacheNode) error {
return g.graphCache.AddNode(tx, node)
g.graphCache.AddNodeFeatures(node)
return nil
},
)
if err != nil {
return nil, err
}
err = g.ForEachChannel(func(info *ChannelEdgeInfo,
policy1, policy2 *ChannelEdgePolicy) error {
g.graphCache.AddChannel(info, policy1, policy2)
return nil
})
if err != nil {
return nil, err
}
log.Debugf("Finished populating in-memory channel graph (took "+
"%v, %s)", time.Since(startTime), g.graphCache.Stats())
}