graph/db: update ForEachChannelCacheable to use new helper

A pure refactor commit which updates ForEachChannelCacheable to make use
of the new sqldb.ExecutePaginatedQuery helper.
This commit is contained in:
Elle Mouton committed 2025-07-31 15:33:08 +02:00
1 parent 61299894e1
commit 2d09acfca2
1 file changed
+18 -27
+18 -27
View File
@@ -1256,7 +1256,7 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
ctx := context.TODO() ctx := context.TODO()
handleChannel := func( handleChannel := func(_ context.Context,
row sqlc.ListChannelsWithPoliciesForCachePaginatedRow) error { row sqlc.ListChannelsWithPoliciesForCachePaginatedRow) error {
node1, node2, err := buildNodeVertices( node1, node2, err := buildNodeVertices(
@@ -1282,43 +1282,34 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
return err return err
} }
if err := cb(edge, pol1, pol2); err != nil { return cb(edge, pol1, pol2)
return err }
}
return nil extractCursor := func(
row sqlc.ListChannelsWithPoliciesForCachePaginatedRow) int64 {
return row.ID
} }
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error { return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
lastID := int64(-1) //nolint:ll
for { queryFunc := func(ctx context.Context, lastID int64,
//nolint:ll limit int32) ([]sqlc.ListChannelsWithPoliciesForCachePaginatedRow,
rows, err := db.ListChannelsWithPoliciesForCachePaginated( error) {
return db.ListChannelsWithPoliciesForCachePaginated(
ctx, sqlc.ListChannelsWithPoliciesForCachePaginatedParams{ ctx, sqlc.ListChannelsWithPoliciesForCachePaginatedParams{
Version: int16(ProtocolV1), Version: int16(ProtocolV1),
ID: lastID, ID: lastID,
Limit: s.cfg.QueryCfg.MaxPageSize, Limit: limit,
}, },
) )
if err != nil {
return err
}
if len(rows) == 0 {
break
}
for _, row := range rows {
err := handleChannel(row)
if err != nil {
return err
}
lastID = row.ID
}
} }
return nil return sqldb.ExecutePaginatedQuery(
ctx, s.cfg.QueryCfg, int64(-1), queryFunc,
extractCursor, handleChannel,
)
}, reset) }, reset)
} }