Skip to content

Commit

Permalink
Implemented AsyncInMemoryDatabase::set in terms of ::batch_set (faceb…
Browse files Browse the repository at this point in the history
  • Loading branch information
cryo28 authored Mar 16, 2024
1 parent 2ce5093 commit f43f03a
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions akd/src/storage/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,15 @@ impl AsyncInMemoryDatabase {
#[async_trait]
impl Database for AsyncInMemoryDatabase {
async fn set(&self, record: DbRecord) -> Result<(), StorageError> {
if let DbRecord::ValueState(value_state) = record {
let username = value_state.username.to_vec();
match self.user_info.get_mut(&username) {
Some(mut states) => {
states.insert(value_state.epoch, value_state);
}
None => {
let mut new_map = HashMap::new();
new_map.insert(value_state.epoch, value_state);
self.user_info.insert(username, new_map);
}
}
} else {
self.db.insert(record.get_full_binary_id(), record);
}

Ok(())
self.batch_set(vec![record], crate::storage::DbSetState::General)
.await
}

async fn batch_set(
&self,
records: Vec<DbRecord>,
_state: crate::storage::DbSetState,
) -> Result<(), StorageError> {
if records.is_empty() {
// nothing to do, save the cycles
return Ok(());
}

for record in records.into_iter() {
if let DbRecord::ValueState(value_state) = record {
let username = value_state.username.to_vec();
Expand Down

0 comments on commit f43f03a

Please sign in to comment.