refactor(sdk): RoomEventCache::subscribe_to_pinned_events no longer takes a write lock.
This patch removes the write lock acquisition in `RoomEventCache::subscribe_to_pinned_events` to replace it by read lock acquisition. Nothing requires a `&mut self` at any point in this flow, since `OnceLock::get_or_init` needs a `&self`. The `RoomEventCacheStateLockWriteGuard::subscribe_to_pinned_events` method is moved onto `RoomEventCacheStateLockReadGuard`.
This commit is contained in:
@@ -249,7 +249,7 @@ impl RoomEventCache {
|
||||
&self,
|
||||
) -> Result<(Vec<Event>, Receiver<RoomEventCacheUpdate>)> {
|
||||
let room = self.inner.weak_room.get().ok_or(EventCacheError::ClientDropped)?;
|
||||
let mut state = self.inner.state.write().await?;
|
||||
let state = self.inner.state.read().await?;
|
||||
|
||||
state.subscribe_to_pinned_events(room).await
|
||||
}
|
||||
@@ -1217,6 +1217,32 @@ mod private {
|
||||
pub fn is_dirty(&self) -> bool {
|
||||
EventCacheStoreLockGuard::is_dirty(&self.store)
|
||||
}
|
||||
|
||||
/// Subscribe to the lazily initialized pinned event cache for this
|
||||
/// room.
|
||||
///
|
||||
/// This is a persisted view over the pinned events of a room. The
|
||||
/// pinned events will be initially loaded from a network
|
||||
/// request to fetch the latest pinned events will be performed,
|
||||
/// to update it as needed. The list of pinned events will also
|
||||
/// be kept up-to-date as new events are pinned, and new related
|
||||
/// events show up from sync or backpagination.
|
||||
///
|
||||
/// This requires the room's event cache to be initialized.
|
||||
pub async fn subscribe_to_pinned_events(
|
||||
&self,
|
||||
room: Room,
|
||||
) -> Result<(Vec<Event>, Receiver<RoomEventCacheUpdate>), EventCacheError> {
|
||||
let pinned_event_cache = self.state.pinned_event_cache.get_or_init(|| {
|
||||
PinnedEventCache::new(
|
||||
room,
|
||||
self.state.linked_chunk_update_sender.clone(),
|
||||
self.state.store.clone(),
|
||||
)
|
||||
});
|
||||
|
||||
pinned_event_cache.subscribe().await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
|
||||
@@ -1816,32 +1842,6 @@ mod private {
|
||||
self.get_or_reload_thread(root).subscribe()
|
||||
}
|
||||
|
||||
/// Subscribe to the lazily initialized pinned event cache for this
|
||||
/// room.
|
||||
///
|
||||
/// This is a persisted view over the pinned events of a room. The
|
||||
/// pinned events will be initially loaded from a network
|
||||
/// request to fetch the latest pinned events will be performed,
|
||||
/// to update it as needed. The list of pinned events will also
|
||||
/// be kept up-to-date as new events are pinned, and new related
|
||||
/// events show up from sync or backpagination.
|
||||
///
|
||||
/// This requires the room's event cache to be initialized.
|
||||
pub async fn subscribe_to_pinned_events(
|
||||
&mut self,
|
||||
room: Room,
|
||||
) -> Result<(Vec<Event>, Receiver<RoomEventCacheUpdate>), EventCacheError> {
|
||||
let pinned_event_cache = self.state.pinned_event_cache.get_or_init(|| {
|
||||
PinnedEventCache::new(
|
||||
room,
|
||||
self.state.linked_chunk_update_sender.clone(),
|
||||
self.state.store.clone(),
|
||||
)
|
||||
});
|
||||
|
||||
pinned_event_cache.subscribe().await
|
||||
}
|
||||
|
||||
/// Back paginate in the given thread.
|
||||
///
|
||||
/// Will always start from the end, unless we previously paginated.
|
||||
|
||||
Reference in New Issue
Block a user