refactor(event cache): spawn a task to handle updates to the event cache store

This commit is contained in:
Benjamin Bouvier
2024-12-10 12:16:32 +01:00
parent 20184552a8
commit 4402f59e74

View File

@@ -723,8 +723,6 @@ mod private {
if !updates.is_empty() {
if let Some(store) = self.store.get() {
let locked = store.lock().await?;
// Strip relations from the `PushItems` updates.
for up in updates.iter_mut() {
match up {
@@ -743,7 +741,28 @@ mod private {
}
}
locked.handle_linked_chunk_updates(&self.room, updates).await?;
// Spawn a task to make sure that all the changes are effectively forwarded to
// the store, even if the call to this method gets aborted.
//
// The store cross-process locking involves an actual mutex, which ensures that
// storing updates happens in the expected order.
let store = store.clone();
let room_id = self.room.clone();
matrix_sdk_common::executor::spawn(async move {
let locked = store.lock().await?;
if let Err(err) =
locked.handle_linked_chunk_updates(&room_id, updates).await
{
error!("unable to handle linked chunk updates: {err}");
}
super::Result::Ok(())
})
.await
.expect("joining failed")?;
}
}