mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
graph/db: update forEachNodeCacheable to use sqldb helper
A pure refactor which updates forEachNodeCacheable to make use of the new sqldb.ExecutePaginatedQuery helper.
This commit is contained in:
@@ -3094,39 +3094,34 @@ func forEachNodeCacheable(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
db SQLQueries,
|
db SQLQueries,
|
||||||
cb func(nodeID int64, nodePub route.Vertex) error) error {
|
cb func(nodeID int64, nodePub route.Vertex) error) error {
|
||||||
|
|
||||||
lastID := int64(-1)
|
handleNode := func(_ context.Context,
|
||||||
|
node sqlc.ListNodeIDsAndPubKeysRow) error {
|
||||||
|
|
||||||
for {
|
var pub route.Vertex
|
||||||
nodes, err := db.ListNodeIDsAndPubKeys(
|
copy(pub[:], node.PubKey)
|
||||||
|
|
||||||
|
return cb(node.ID, pub)
|
||||||
|
}
|
||||||
|
|
||||||
|
queryFunc := func(ctx context.Context, lastID int64,
|
||||||
|
limit int32) ([]sqlc.ListNodeIDsAndPubKeysRow, error) {
|
||||||
|
|
||||||
|
return db.ListNodeIDsAndPubKeys(
|
||||||
ctx, sqlc.ListNodeIDsAndPubKeysParams{
|
ctx, sqlc.ListNodeIDsAndPubKeysParams{
|
||||||
Version: int16(ProtocolV1),
|
Version: int16(ProtocolV1),
|
||||||
ID: lastID,
|
ID: lastID,
|
||||||
Limit: cfg.MaxPageSize,
|
Limit: limit,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to fetch nodes: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(nodes) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, node := range nodes {
|
|
||||||
var pub route.Vertex
|
|
||||||
copy(pub[:], node.PubKey)
|
|
||||||
|
|
||||||
if err := cb(node.ID, pub); err != nil {
|
|
||||||
return fmt.Errorf("forEachNodeCacheable "+
|
|
||||||
"callback failed for node(id=%d): %w",
|
|
||||||
node.ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
lastID = node.ID
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
extractCursor := func(row sqlc.ListNodeIDsAndPubKeysRow) int64 {
|
||||||
|
return row.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
return sqldb.ExecutePaginatedQuery(
|
||||||
|
ctx, cfg, int64(-1), queryFunc, extractCursor, handleNode,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// forEachNodeChannel iterates through all channels of a node, executing
|
// forEachNodeChannel iterates through all channels of a node, executing
|
||||||
|
Reference in New Issue
Block a user