mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
graph/db: convert NodeUpdatesInHorizon to use iterators
In this commit, we refactor the NodeUpdatesInHorizon 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. The new implementation uses Go 1.23's iter.Seq type to provide a standard iterator interface. The method now supports configurable batch sizes through functional options, allowing fine-tuned control over memory usage and performance characteristics. Rather than reading all the entries from disk into memory (before this commit, we did consult the cache for most entries, skipping the disk hits), we now expose a chunked iterator instead. We also make the process of filtering out public nodes first class. This saves many newly created db transactions later.
This commit is contained in:
@@ -201,7 +201,7 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, nodeAnn := range nodeAnnsInHorizon {
|
||||
for nodeAnn := range nodeAnnsInHorizon {
|
||||
// If this node has not been seen in the above channels, we can
|
||||
// skip sending its NodeAnnouncement.
|
||||
if _, seen := nodesFromChan[nodeAnn.PubKeyBytes]; !seen {
|
||||
|
||||
Reference in New Issue
Block a user