mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-24 13:06:43 +01:00
channeldb: speed up graph cache loading
Use the optimized ForEachChannel method to reduce the graph cache loading time.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user