@@ -370,14 +370,14 @@ impl EventCache {
370370
371371 // Phase 1: under the room state write lock, collect cache handles and
372372 // perform all room-linked-chunk mutations. We deliberately do NOT call
373- // replace_utds() on event-focused/pinned caches here to avoid an ABBA deadlock:
374- // pagination holds an event-focused cache lock and then tries to acquire the
375- // room state lock (via `save_events`), while this method would hold the
376- // room state lock and try to acquire event-focused cache locks.
377- let ( pinned_cache, ef_caches) = {
373+ // replace_utds() on event-focused/pinned-evenst caches here to avoid an ABBA
374+ // deadlock: pagination holds an event-focused cache lock and then tries
375+ // to acquire the room state lock (via `save_events`), while this method
376+ // would hold the room state lock and try to acquire event-focused cache
377+ // locks.
378+ let ef_caches = {
378379 let mut state = room_cache. state ( ) . write ( ) . await ?;
379380
380- let pinned_cache = state. pinned_events_cache ( ) . cloned ( ) ;
381381 let ef_caches: Vec < _ > = state. event_focused_caches ( ) . cloned ( ) . collect ( ) ;
382382
383383 // Consider the room linked chunk.
@@ -416,15 +416,17 @@ impl EventCache {
416416 Some ( RoomEventCacheGenericUpdate { room_id : room_id. to_owned ( ) } ) ,
417417 ) ;
418418
419- ( pinned_cache , ef_caches)
419+ ef_caches
420420 } ;
421421 // Room state write lock is dropped here.
422422
423- // Phase 2: replace UTDs in pinned and event-focused caches WITHOUT
424- // holding the room state lock. These caches have their own internal
425- // locks and don't need the room state lock.
426- if let Some ( pinned_cache) = pinned_cache {
427- pinned_cache. replace_utds ( & events) . await ?;
423+ // Phase 2: replace UTDs in pinned-events and event-focused caches
424+ // WITHOUT holding the room state lock. These caches have their own
425+ // internal locks and don't need the room state lock.
426+ if let Ok ( Some ( pinned_events_cache) ) =
427+ self . pinned_events_without_initialisation ( room_id) . await
428+ {
429+ pinned_events_cache. replace_utds ( & events) . await ?;
428430 }
429431
430432 // TODO: This ain't great for performance; there shouldn't be that many
0 commit comments