Commit c72dc01ad0dd
tarball3 files changed+21-17
@@ -146,16 +146,6 @@ impl Caches {
146146
pub async fn prepare_to_reset(&mut self) -> Result<ResetCaches<'_>> {147147
ResetCaches::new(self).await148148
}149
-150
- /// Get all events from all the event caches manged by this [`Cacches`].151
- ///152
- /// Events can be duplicated if present in different event caches.153
- #[cfg(feature = "e2e-encryption")]154
- pub async fn all_events(&self) -> Result<impl Iterator<Item = Event>> {155
- let events_from_room = self.room.events().await?;156
-157
- Ok(events_from_room.into_iter())158
- }159149
}160150
161151
/// Type holding exclusive locks over all event caches managed by a@@ -253,7 +253,7 @@ impl RoomEventCache {
253253
mut cancellation: watch::Receiver<bool>,254254
) -> Result<RecentHistoryOutcome> {255255
let (anchor, retained) = {256
- let mut state = self.inner.state.write().await?;256
+ let state = self.inner.state.write().await?;257257
let retained: HashSet<_> = state258258
.room_linked_chunk()259259
.events()@@ -281,14 +281,28 @@ impl EventCache {
281281
Ok(events.into_iter().filter_map(filter_timeline_event_to_utd).collect())282282
}283283
284
+ /// The rooms the event cache holds, taken out of `by_room` before any of them is awaited.285
+ ///286
+ /// A slow room (a full history load from IndexedDB) would otherwise keep the global lock, and287
+ /// tokio queues new readers behind a waiting room creation, so every room access stalls.288
+ async fn rooms_in_memory(&self) -> Vec<(OwnedRoomId, crate::event_cache::RoomEventCache)> {289
+ self.inner290
+ .by_room291
+ .read()292
+ .await293
+ .iter()294
+ .map(|(room_id, caches)| (room_id.clone(), caches.room.clone()))295
+ .collect()296
+ }297
+284298
/// Retrieve a set of events that we weren't able to decrypt from the memory285299
/// of the event cache.286300
async fn get_utds_from_memory(&self) -> BTreeMap<OwnedRoomId, Vec<EventIdAndUtd>> {287301
let mut utds = BTreeMap::new();288302
289
- for (room_id, caches) in self.inner.by_room.read().await.iter() {290
- let room_utds: Vec<_> = caches291
- .all_events()303
+ for (room_id, room) in self.rooms_in_memory().await {304
+ let room_utds: Vec<_> = room305
+ .events()292306
.await293307
.into_iter()294308
.flatten()@@ -324,9 +338,9 @@ impl EventCache {
324338
) -> BTreeMap<OwnedRoomId, Vec<EventIdAndEvent>> {325339
let mut decrypted_events = BTreeMap::new();326340
327
- for (room_id, caches) in self.inner.by_room.read().await.iter() {328
- let room_utds: Vec<_> = caches329
- .all_events()341
+ for (room_id, room) in self.rooms_in_memory().await {342
+ let room_utds: Vec<_> = room343
+ .events()330344
.await331345
.into_iter()332346
.flatten()