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 committed 2025-09-26 16:57:11 -07:00
1 parent 1d6d54e5db
commit 069888b51a
7 files changed
+254 -86

No files matched your search

+4 -2
View File
@@ -2028,10 +2028,11 @@ func TestChanUpdatesInHorizon(t *testing.T) {
// If we issue an arbitrary query before any channel updates are
// inserted in the database, we should get zero results.
chanUpdates, err := graph.ChanUpdatesInHorizon(
chanUpdatesIter, err := graph.ChanUpdatesInHorizon(
time.Unix(999, 0), time.Unix(9999, 0),
)
require.NoError(t, err, "unable to updates for updates")
chanUpdates := fn.Collect(chanUpdatesIter)
if len(chanUpdates) != 0 {
t.Fatalf("expected 0 chan updates, instead got %v",
len(chanUpdates))
@@ -2144,12 +2145,13 @@ func TestChanUpdatesInHorizon(t *testing.T) {
},
}
for _, queryCase := range queryCases {
resp, err := graph.ChanUpdatesInHorizon(
respIter, err := graph.ChanUpdatesInHorizon(
queryCase.start, queryCase.end,
)
if err != nil {
t.Fatalf("unable to query for updates: %v", err)
}
resp := fn.Collect(respIter)
if len(resp) != len(queryCase.resp) {
t.Fatalf("expected %v chans, got %v chans",