-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add methods to PrefixIterator to support iterating from a specific key #9313
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the PR is correct, but incomplete. I don't see any change in public interfaces like IterableStorageMap
etc. My assumption was that there'd be a new fn iter_from()
added to these traits, which would create an iterating type from KeyPrefixIterator
or similar types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good but I would prefer having
- some more tests
- order specified
- some naming nitpicks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
fn drain_prefix(k1: impl EncodeLike<K1>) -> Self::PrefixIterator { | ||
let mut iterator = Self::iter_prefix(k1); | ||
iterator.drain = true; | ||
iterator | ||
} | ||
|
||
fn iter() -> Self::Iterator { | ||
Self::iter_from(G::prefix_hash()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wee bit strange here. iter_from
is already reading let prefix = G::prefix_hash();
, but we pass in G::prefix_hash()
to it again. I'd make the starting_raw_key
an Option
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can just revert this and implement iter_from
in terms of iter
by calling set_previous_key
on the resulting PrefixIterator
.
@@ -144,10 +144,15 @@ impl< | |||
|
|||
/// Enumerate all elements in the map. | |||
fn iter() -> Self::Iterator { | |||
Self::iter_from(G::prefix_hash()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same grumble.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got one minor note, otherwise looks good now.
bot merge |
Waiting for commit status. |
Fixes #9213.
This adds methods that aid in paginating storage iterators. I imagine that this will be used heavily in storage migrations that span multiple blocks, or other sorts of consensus mechanisms that span multiple blocks and require interaction with storage.