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

+9 -2
View File
@@ -933,7 +933,8 @@ func (s *SQLStore) ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
//
// NOTE: This is part of the V1Store interface.
func (s *SQLStore) ChanUpdatesInHorizon(startTime,
endTime time.Time) ([]ChannelEdge, error) {
endTime time.Time,
opts ...IteratorOption) (iter.Seq[ChannelEdge], error) {
s.cacheMu.Lock()
defer s.cacheMu.Unlock()
@@ -1033,7 +1034,13 @@ func (s *SQLStore) ChanUpdatesInHorizon(startTime,
"horizon (%s, %s)", startTime, endTime)
}
return edges, nil
return func(yield func(ChannelEdge) bool) {
for _, edge := range edges {
if !yield(edge) {
return
}
}
}, nil
}
// ForEachNodeCached is similar to forEachNode, but it returns DirectedChannel