remote-externalities: batch insert key/values (#14004)

* add batch inserting into remote externalities

* use into_iter

* remove redundant comment

* redundant batch insert

* avoid extra vec allocations
This commit is contained in:
Liam Aharon
2023-04-27 18:12:29 +10:00
committed by GitHub
parent 34780b1b2b
commit 27f89d653b
2 changed files with 32 additions and 28 deletions
@@ -132,6 +132,17 @@ where
self.offchain_db.clone()
}
/// Batch insert key/values into backend
pub fn batch_insert<I>(&mut self, kvs: I)
where
I: IntoIterator<Item = (StorageKey, StorageValue)>,
{
self.backend.insert(
Some((None, kvs.into_iter().map(|(k, v)| (k, Some(v))).collect())),
self.state_version,
);
}
/// Insert key/value into backend
pub fn insert(&mut self, k: StorageKey, v: StorageValue) {
self.backend.insert(vec![(None, vec![(k, Some(v))])], self.state_version);