mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Frame remove_all with size limit. (#9106)
* remove prefixed content with limit. * test match * factor comment and factor ext limit removal. * fix benchmark Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -216,13 +216,13 @@ impl Externalities for BasicExternalities {
|
||||
(true, num_removed as u32)
|
||||
}
|
||||
|
||||
fn clear_prefix(&mut self, prefix: &[u8]) {
|
||||
fn clear_prefix(&mut self, prefix: &[u8], _limit: Option<u32>) -> (bool, u32) {
|
||||
if is_child_storage_key(prefix) {
|
||||
warn!(
|
||||
target: "trie",
|
||||
"Refuse to clear prefix that is part of child storage key via main storage"
|
||||
);
|
||||
return;
|
||||
return (false, 0);
|
||||
}
|
||||
|
||||
let to_remove = self.inner.top.range::<[u8], _>((Bound::Included(prefix), Bound::Unbounded))
|
||||
@@ -231,16 +231,19 @@ impl Externalities for BasicExternalities {
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let num_removed = to_remove.len();
|
||||
for key in to_remove {
|
||||
self.inner.top.remove(&key);
|
||||
}
|
||||
(true, num_removed as u32)
|
||||
}
|
||||
|
||||
fn clear_child_prefix(
|
||||
&mut self,
|
||||
child_info: &ChildInfo,
|
||||
prefix: &[u8],
|
||||
) {
|
||||
_limit: Option<u32>,
|
||||
) -> (bool, u32) {
|
||||
if let Some(child) = self.inner.children_default.get_mut(child_info.storage_key()) {
|
||||
let to_remove = child.data.range::<[u8], _>((Bound::Included(prefix), Bound::Unbounded))
|
||||
.map(|(k, _)| k)
|
||||
@@ -248,9 +251,13 @@ impl Externalities for BasicExternalities {
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let num_removed = to_remove.len();
|
||||
for key in to_remove {
|
||||
child.data.remove(&key);
|
||||
}
|
||||
(true, num_removed as u32)
|
||||
} else {
|
||||
(true, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user