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