Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another proposals to multi get PR #2420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/storage/src/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ where
where
Iter: 'a + Iterator<Item = &'a M::Key> + Send,
M::Key: 'a,
Self::KeyCodec: 'a,
{
let keys = keys
.map(|key| Self::KeyCodec::encode(key).into_bytes())
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/src/blueprint/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
set.map(|(key, value)| {
let key_encoder =
<M::Blueprint as BlueprintInspect<M, S>>::KeyCodec::encode(key);
let key_bytes = key_encoder.as_bytes().to_vec();
let key_bytes = key_encoder.into_bytes();
let value =
<M::Blueprint as BlueprintInspect<M, S>>::ValueCodec::encode_as_value(
value,
Expand All @@ -158,7 +158,7 @@ where
set.map(|key| {
let key_encoder =
<M::Blueprint as BlueprintInspect<M, S>>::KeyCodec::encode(key);
let key_bytes = key_encoder.as_bytes().to_vec();
let key_bytes = key_encoder.into_bytes();
(key_bytes, WriteOperation::Remove)
}),
)
Expand Down
10 changes: 4 additions & 6 deletions crates/storage/src/blueprint/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ where

let encoded_set = set
.map(|(key, value)| {
let key = KeyCodec::encode(key).as_bytes().into_owned();
let key = KeyCodec::encode(key).into_bytes();
let value = ValueCodec::encode(value).as_bytes().into_owned();
(key, value)
})
Expand All @@ -346,9 +346,7 @@ where
)?;

let nodes = nodes.iter().map(|(key, value)| {
let key = NodeKeyCodec::<S, Nodes>::encode(key)
.as_bytes()
.into_owned();
let key = NodeKeyCodec::<S, Nodes>::encode(key).into_bytes();
let value = NodeValueCodec::<S, Nodes>::encode_as_value(value);
(key, WriteOperation::Insert(value))
});
Expand Down Expand Up @@ -392,7 +390,7 @@ where

let encoded_set = set
.map(|(key, value)| {
let key = KeyCodec::encode(key).as_bytes().into_owned();
let key = KeyCodec::encode(key).into_bytes();
let value = ValueCodec::encode(value).as_bytes().into_owned();
(key, value)
})
Expand Down Expand Up @@ -449,7 +447,7 @@ where
.map_err(|err| StorageError::Other(anyhow::anyhow!("{err:?}")))?;

let encoded_set = set
.map(|key| KeyCodec::encode(key).as_bytes().into_owned())
.map(|key| KeyCodec::encode(key).into_bytes())
.collect_vec();

for key_bytes in encoded_set.iter() {
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait Encoder<'a> {
/// flexibility and more performant encoding, allowing the use of slices and arrays
/// instead of vectors in some cases. Since the [`Encoder`] returns `Cow<[u8]>`,
/// it is always possible to take ownership of the serialized value.
pub trait Encode<T: ?Sized> {
pub trait Encode<T: ?Sized>: 'static {
/// The encoder type that stores serialized object.
type Encoder<'a>: Encoder<'a>
where
Expand Down
8 changes: 6 additions & 2 deletions crates/storage/src/kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ pub enum WriteOperation {
#[impl_tools::autoimpl(for<T: trait> &mut T, Box<T>)]
pub trait BatchOperations: KeyValueMutate {
/// Writes the batch of the entries into the storage.
fn batch_write<I>(&mut self, column: Self::Column, entries: I) -> StorageResult<()>
fn batch_write<'a, I>(
&mut self,
column: Self::Column,
entries: I,
) -> StorageResult<()>
where
I: Iterator<Item = (Vec<u8>, WriteOperation)>;
I: Iterator<Item = (Cow<'a, [u8]>, WriteOperation)> + 'a;
}
8 changes: 6 additions & 2 deletions crates/storage/src/structured_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ impl<S> BatchOperations for StructuredStorage<S>
where
S: BatchOperations,
{
fn batch_write<I>(&mut self, column: Self::Column, entries: I) -> StorageResult<()>
fn batch_write<'a, I>(
&mut self,
column: Self::Column,
entries: I,
) -> StorageResult<()>
where
I: Iterator<Item = (Vec<u8>, WriteOperation)>,
I: Iterator<Item = (Cow<'a, [u8]>, WriteOperation)> + 'a,
{
self.inner.batch_write(column, entries)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/storage/src/transactional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,13 @@ where
Column: StorageColumn,
S: KeyValueInspect<Column = Column>,
{
fn batch_write<I>(&mut self, column: Column, entries: I) -> StorageResult<()>
fn batch_write<'a, I>(&mut self, column: Column, entries: I) -> StorageResult<()>
where
I: Iterator<Item = (Vec<u8>, WriteOperation)>,
I: Iterator<Item = (Cow<'a, [u8]>, WriteOperation)> + 'a,
{
let btree = self.changes.entry(column.id()).or_default();
entries.for_each(|(key, operation)| {
btree.insert(key.into(), operation);
btree.insert(key.to_vec().into(), operation);
});
Ok(())
}
Expand Down
Loading