graph/db: let ForEachNodeCached take a context
This commit is contained in:
8 files changed
+15
-14
No files matched your search
+4
-3
@@ -245,14 +245,15 @@ func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error {
|
||||
// graph, executing the passed callback with each node encountered.
|
||||
//
|
||||
// NOTE: The callback contents MUST not be modified.
|
||||
func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
func (c *ChannelGraph) ForEachNodeCached(ctx context.Context,
|
||||
cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
|
||||
if c.graphCache != nil {
|
||||
return c.graphCache.ForEachNode(cb)
|
||||
}
|
||||
|
||||
return c.V1Store.ForEachNodeCached(cb)
|
||||
return c.V1Store.ForEachNodeCached(ctx, cb)
|
||||
}
|
||||
|
||||
// AddLightningNode adds a vertex/node to the graph database. If the node is not
|
||||
|
||||
@@ -1358,7 +1358,7 @@ func TestGraphTraversal(t *testing.T) {
|
||||
// set of channels (to force the fall back), we should find all the
|
||||
// channel as well as the nodes included.
|
||||
graph.graphCache = nil
|
||||
err := graph.ForEachNodeCached(func(node route.Vertex,
|
||||
err := graph.ForEachNodeCached(ctx, func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error {
|
||||
|
||||
if _, ok := nodeIndex[node]; !ok {
|
||||
|
||||
@@ -91,7 +91,7 @@ type V1Store interface { //nolint:interfacebloat
|
||||
// DirectedChannel data to the call-back.
|
||||
//
|
||||
// NOTE: The callback contents MUST not be modified.
|
||||
ForEachNodeCached(cb func(node route.Vertex,
|
||||
ForEachNodeCached(ctx context.Context, cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error
|
||||
|
||||
// ForEachNode iterates through all the stored vertices/nodes in the
|
||||
|
||||
@@ -667,8 +667,9 @@ func (c *KVStore) FetchNodeFeatures(nodePub route.Vertex) (
|
||||
// data to the call-back.
|
||||
//
|
||||
// NOTE: The callback contents MUST not be modified.
|
||||
func (c *KVStore) ForEachNodeCached(cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
func (c *KVStore) ForEachNodeCached(_ context.Context,
|
||||
cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
|
||||
// Otherwise call back to a version that uses the database directly.
|
||||
// We'll iterate over each node, then the set of channels for each
|
||||
|
||||
@@ -1102,10 +1102,9 @@ func (s *SQLStore) ChanUpdatesInHorizon(startTime,
|
||||
// NOTE: The callback contents MUST not be modified.
|
||||
//
|
||||
// NOTE: part of the V1Store interface.
|
||||
func (s *SQLStore) ForEachNodeCached(cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
|
||||
var ctx = context.TODO()
|
||||
func (s *SQLStore) ForEachNodeCached(ctx context.Context,
|
||||
cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
|
||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
return forEachNodeCacheable(ctx, db, func(nodeID int64,
|
||||
|
||||
Reference in new issue
Block a user