graph/db: let ForEachNodeCached maybe fetch node addresses
Here we adjust the ForEachNodeCached graph DB method to pass in a node's addresses into the provided call-back if requested. This will allow us to improve the performance of node/channel iteration in the autopilot subserver.
This commit is contained in:
9 files changed
+96
-26
No files matched your search
+13
-6
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -248,15 +249,21 @@ func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error,
|
||||
// graph, executing the passed callback with each node encountered.
|
||||
//
|
||||
// NOTE: The callback contents MUST not be modified.
|
||||
func (c *ChannelGraph) ForEachNodeCached(ctx context.Context,
|
||||
cb func(node route.Vertex, chans map[uint64]*DirectedChannel) error,
|
||||
reset func()) error {
|
||||
func (c *ChannelGraph) ForEachNodeCached(ctx context.Context, withAddrs bool,
|
||||
cb func(ctx context.Context, node route.Vertex, addrs []net.Addr,
|
||||
chans map[uint64]*DirectedChannel) error, reset func()) error {
|
||||
|
||||
if c.graphCache != nil {
|
||||
return c.graphCache.ForEachNode(cb)
|
||||
if !withAddrs && c.graphCache != nil {
|
||||
return c.graphCache.ForEachNode(
|
||||
func(node route.Vertex,
|
||||
channels map[uint64]*DirectedChannel) error {
|
||||
|
||||
return cb(ctx, node, nil, channels)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return c.V1Store.ForEachNodeCached(ctx, cb, reset)
|
||||
return c.V1Store.ForEachNodeCached(ctx, withAddrs, cb, reset)
|
||||
}
|
||||
|
||||
// AddLightningNode adds a vertex/node to the graph database. If the node is not
|
||||
|
||||
Reference in new issue
Block a user