crypto: Make the save device method of the store accept a slice of devices.
parent
157dc86b61
commit
e33fd098bc
|
@ -460,16 +460,12 @@ impl OlmMachine {
|
|||
for device_id in deleted_devices {
|
||||
if let Some(device) = stored_devices.get(device_id) {
|
||||
device.mark_as_deleted();
|
||||
// TODO change this to a bulk deletion.
|
||||
self.store.delete_device(device).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO change this to a bulk operation.
|
||||
for device in &changed_devices {
|
||||
self.store.save_device(device.clone()).await?;
|
||||
}
|
||||
self.store.save_devices(&changed_devices).await?;
|
||||
|
||||
Ok(changed_devices)
|
||||
}
|
||||
|
@ -1519,8 +1515,8 @@ mod test {
|
|||
|
||||
let alice_deivce = Device::from(&alice);
|
||||
let bob_device = Device::from(&bob);
|
||||
alice.store.save_device(bob_device).await.unwrap();
|
||||
bob.store.save_device(alice_deivce).await.unwrap();
|
||||
alice.store.save_devices(&[bob_device]).await.unwrap();
|
||||
bob.store.save_devices(&[alice_deivce]).await.unwrap();
|
||||
|
||||
(alice, bob, otk)
|
||||
}
|
||||
|
|
|
@ -97,8 +97,11 @@ impl CryptoStore for MemoryStore {
|
|||
Ok(self.devices.user_devices(user_id))
|
||||
}
|
||||
|
||||
async fn save_device(&self, device: Device) -> Result<()> {
|
||||
self.devices.add(device);
|
||||
async fn save_devices(&self, devices: &[Device]) -> Result<()> {
|
||||
for device in devices {
|
||||
self.devices.add(device.clone());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +171,7 @@ mod test {
|
|||
let device = get_device();
|
||||
let store = MemoryStore::new();
|
||||
|
||||
store.save_device(device.clone()).await.unwrap();
|
||||
store.save_devices(&[device.clone()]).await.unwrap();
|
||||
|
||||
let loaded_device = store
|
||||
.get_device(device.user_id(), device.device_id())
|
||||
|
|
|
@ -126,12 +126,12 @@ pub trait CryptoStore: Debug + Send + Sync {
|
|||
/// * `user` - The user that should be marked as tracked.
|
||||
async fn add_user_for_tracking(&mut self, user: &UserId) -> Result<bool>;
|
||||
|
||||
/// Save the given device in the store.
|
||||
/// Save the given devices in the store.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `device` - The device that should be stored.
|
||||
async fn save_device(&self, device: Device) -> Result<()>;
|
||||
async fn save_devices(&self, devices: &[Device]) -> Result<()>;
|
||||
|
||||
/// Delete the given device from the store.
|
||||
///
|
||||
|
|
|
@ -608,9 +608,14 @@ impl CryptoStore for SqliteStore {
|
|||
Ok(self.tracked_users.insert(user.clone()))
|
||||
}
|
||||
|
||||
async fn save_device(&self, device: Device) -> Result<()> {
|
||||
self.devices.add(device.clone());
|
||||
self.save_device_helper(device).await
|
||||
async fn save_devices(&self, devices: &[Device]) -> Result<()> {
|
||||
// TODO turn this into a bulk transaction.
|
||||
for device in devices {
|
||||
self.devices.add(device.clone());
|
||||
self.save_device_helper(device.clone()).await?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_device(&self, device: Device) -> Result<()> {
|
||||
|
@ -937,7 +942,7 @@ mod test {
|
|||
let (_account, store, dir) = get_loaded_store().await;
|
||||
let device = get_device();
|
||||
|
||||
store.save_device(device.clone()).await.unwrap();
|
||||
store.save_devices(&[device.clone()]).await.unwrap();
|
||||
|
||||
drop(store);
|
||||
|
||||
|
|
Loading…
Reference in New Issue