graph/db: convert ChanUpdatesInHorizon to use iterators

In this commit, we refactor the ChanUpdatesInHorizon method to return
an iterator instead of a slice. This change significantly reduces
memory usage when dealing with large result sets by allowing callers to
process items incrementally rather than loading everything into memory
at once.
This commit is contained in:
Olaoluwa Osuntokun
2025-08-04 17:16:21 -07:00
parent 1d6d54e5db
commit 069888b51a
7 changed files with 254 additions and 86 deletions

View File

@@ -2,6 +2,7 @@ package graph
import (
"context"
"iter"
"time"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -152,8 +153,9 @@ type DB interface {
// ChanUpdatesInHorizon returns all the known channel edges which have
// at least one edge that has an update timestamp within the specified
// horizon.
ChanUpdatesInHorizon(startTime, endTime time.Time) (
[]graphdb.ChannelEdge, error)
ChanUpdatesInHorizon(startTime, endTime time.Time,
opts ...graphdb.IteratorOption) (
iter.Seq[graphdb.ChannelEdge], error)
// DeleteChannelEdges removes edges with the given channel IDs from the
// database and marks them as zombies. This ensures that we're unable to