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:
5 files changed
+206
-32
No files matched your search
@@ -2,6 +2,7 @@ package graphdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"iter"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -109,8 +110,8 @@ type V1Store interface { //nolint:interfacebloat
|
||||
// an update timestamp within the passed range. This method can be used
|
||||
// by two nodes to quickly determine if they have the same set of up to
|
||||
// date node announcements.
|
||||
NodeUpdatesInHorizon(startTime,
|
||||
endTime time.Time) ([]models.Node, error)
|
||||
NodeUpdatesInHorizon(startTime, endTime time.Time,
|
||||
opts ...IteratorOption) (iter.Seq[models.Node], error)
|
||||
|
||||
// FetchNode attempts to look up a target node by its identity
|
||||
// public key. If the node isn't found in the database, then
|
||||
|
||||
Reference in new issue
Block a user