mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-08-02 19:12:53 -04:00
refactor(sdk): Rename PinnedEventCache to PinnedEventsCache.
This patch renames `PinnedEventCache` to `PinnedEventsCache` (and same for all types having `PinnedEventCache` as a prefix). Why? Because it's a cache about _pinned-events_, not a single _pinned-event_ :-).
This commit is contained in:
@@ -1463,7 +1463,7 @@ impl TimelineController {
|
||||
.client()
|
||||
.task_monitor()
|
||||
.spawn_infinite_task(
|
||||
"timeline::pinned_event_cache_updates",
|
||||
"timeline::pinned_events_cache_updates",
|
||||
pinned_events_task(event_cache.clone(), self.clone(), pinned_events_recv),
|
||||
)
|
||||
.abort_on_drop();
|
||||
|
||||
@@ -44,7 +44,7 @@ use super::{
|
||||
};
|
||||
use crate::{Room, client::WeakClient, config::RequestConfig, room::WeakRoom};
|
||||
|
||||
pub(in super::super) struct PinnedEventCacheState {
|
||||
pub(in super::super) struct PinnedEventsCacheState {
|
||||
/// The ID of the room owning this list of pinned events.
|
||||
room_id: OwnedRoomId,
|
||||
|
||||
@@ -69,16 +69,16 @@ pub(in super::super) struct PinnedEventCacheState {
|
||||
linked_chunk_update_sender: Sender<RoomEventCacheLinkedChunkUpdate>,
|
||||
}
|
||||
|
||||
impl lock::Store for PinnedEventCacheState {
|
||||
impl lock::Store for PinnedEventsCacheState {
|
||||
fn store(&self) -> &EventCacheStoreLock {
|
||||
&self.store
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl fmt::Debug for PinnedEventCacheState {
|
||||
impl fmt::Debug for PinnedEventsCacheState {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("PinnedEventCacheState")
|
||||
f.debug_struct("PinnedEventsCacheState")
|
||||
.field("room_id", &self.room_id)
|
||||
.field("chunk", &self.chunk)
|
||||
.finish_non_exhaustive()
|
||||
@@ -89,12 +89,12 @@ impl fmt::Debug for PinnedEventCacheState {
|
||||
///
|
||||
/// This contains all the inner mutable states that ought to be updated at
|
||||
/// the same time.
|
||||
pub type PinnedEventCacheStateLock = lock::StateLock<PinnedEventCacheState>;
|
||||
pub type PinnedEventsCacheStateLock = lock::StateLock<PinnedEventsCacheState>;
|
||||
|
||||
pub type PinnedEventCacheStateLockWriteGuard<'a> =
|
||||
lock::StateLockWriteGuard<'a, PinnedEventCacheState>;
|
||||
pub type PinnedEventsCacheStateLockWriteGuard<'a> =
|
||||
lock::StateLockWriteGuard<'a, PinnedEventsCacheState>;
|
||||
|
||||
impl<'a> lock::Reload for PinnedEventCacheStateLockWriteGuard<'a> {
|
||||
impl<'a> lock::Reload for PinnedEventsCacheStateLockWriteGuard<'a> {
|
||||
async fn reload(&mut self) -> Result<()> {
|
||||
self.reload_from_storage().await?;
|
||||
|
||||
@@ -102,7 +102,7 @@ impl<'a> lock::Reload for PinnedEventCacheStateLockWriteGuard<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PinnedEventCacheStateLockWriteGuard<'a> {
|
||||
impl<'a> PinnedEventsCacheStateLockWriteGuard<'a> {
|
||||
/// Reload all the pinned events from storage, replacing the current linked
|
||||
/// chunk.
|
||||
async fn reload_from_storage(&mut self) -> Result<()> {
|
||||
@@ -190,7 +190,7 @@ impl<'a> PinnedEventCacheStateLockWriteGuard<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl PinnedEventCacheState {
|
||||
impl PinnedEventsCacheState {
|
||||
/// Return a list of the current event IDs in this linked chunk.
|
||||
fn current_event_ids(&self) -> Vec<OwnedEventId> {
|
||||
self.chunk.events().filter_map(|(_position, event)| event.event_id()).collect()
|
||||
@@ -201,16 +201,16 @@ impl PinnedEventCacheState {
|
||||
///
|
||||
/// This is cheap to clone, because it's a shallow data type.
|
||||
#[derive(Clone)]
|
||||
pub struct PinnedEventCache {
|
||||
state: Arc<PinnedEventCacheStateLock>,
|
||||
pub struct PinnedEventsCache {
|
||||
state: Arc<PinnedEventsCacheStateLock>,
|
||||
|
||||
/// The task handling the refreshing of pinned events for this specific
|
||||
/// room.
|
||||
_task: Arc<BackgroundTaskHandle>,
|
||||
}
|
||||
|
||||
impl PinnedEventCache {
|
||||
/// Creates a new [`PinnedEventCache`] for the given room.
|
||||
impl PinnedEventsCache {
|
||||
/// Creates a new [`PinnedEventsCache`] for the given room.
|
||||
pub(in super::super) fn new(
|
||||
room: Room,
|
||||
linked_chunk_update_sender: Sender<RoomEventCacheLinkedChunkUpdate>,
|
||||
@@ -223,8 +223,8 @@ impl PinnedEventCache {
|
||||
let chunk = EventLinkedChunk::new();
|
||||
|
||||
let state =
|
||||
PinnedEventCacheState { room_id, chunk, sender, linked_chunk_update_sender, store };
|
||||
let state = Arc::new(PinnedEventCacheStateLock::new_inner(state));
|
||||
PinnedEventsCacheState { room_id, chunk, sender, linked_chunk_update_sender, store };
|
||||
let state = Arc::new(PinnedEventsCacheStateLock::new_inner(state));
|
||||
|
||||
let task = Arc::new(
|
||||
room.client()
|
||||
@@ -356,7 +356,7 @@ impl PinnedEventCache {
|
||||
}
|
||||
|
||||
#[instrument(fields(%room_id = room.room_id()), skip(room, state))]
|
||||
async fn pinned_event_listener_task(room: Room, state: Arc<PinnedEventCacheStateLock>) {
|
||||
async fn pinned_event_listener_task(room: Room, state: Arc<PinnedEventsCacheStateLock>) {
|
||||
debug!("pinned events listener task started");
|
||||
|
||||
let reload_from_network = async |room: Room| {
|
||||
@@ -549,9 +549,9 @@ impl PinnedEventCache {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for PinnedEventCache {
|
||||
impl fmt::Debug for PinnedEventsCache {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("PinnedEventCache").finish_non_exhaustive()
|
||||
f.debug_struct("PinnedEventsCache").finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ use super::{
|
||||
event_linked_chunk::EventLinkedChunk,
|
||||
lock,
|
||||
pagination::SharedPaginationStatus,
|
||||
pinned_events::PinnedEventCache,
|
||||
pinned_events::PinnedEventsCache,
|
||||
read_receipts::compute_unread_counts,
|
||||
},
|
||||
EventsOrigin, RoomEventCacheGenericUpdate, RoomEventCacheLinkedChunkUpdate,
|
||||
@@ -111,7 +111,7 @@ pub struct RoomEventCacheState {
|
||||
event_focused_caches: HashMap<EventFocusedCacheKey, EventFocusedCache>,
|
||||
|
||||
/// Cache for pinned events in this room, initialized on-demand.
|
||||
pinned_event_cache: OnceLock<PinnedEventCache>,
|
||||
pinned_events_cache: OnceLock<PinnedEventsCache>,
|
||||
|
||||
pagination_status: SharedObservable<SharedPaginationStatus>,
|
||||
|
||||
@@ -260,7 +260,7 @@ impl LockedRoomEventCacheState {
|
||||
room_version_rules,
|
||||
waited_for_initial_prev_token: false,
|
||||
subscriber_count: Default::default(),
|
||||
pinned_event_cache: OnceLock::new(),
|
||||
pinned_events_cache: OnceLock::new(),
|
||||
automatic_pagination,
|
||||
}))
|
||||
}
|
||||
@@ -282,8 +282,8 @@ impl<'a> lock::Reload for RoomEventCacheStateLockWriteGuard<'a> {
|
||||
self.shrink_to_last_chunk().await?;
|
||||
|
||||
// Reload the pinned-events.
|
||||
if let Some(pinned_event_cache) = self.pinned_event_cache.get_mut() {
|
||||
pinned_event_cache.reload().await?;
|
||||
if let Some(pinned_events_cache) = self.pinned_events_cache.get_mut() {
|
||||
pinned_events_cache.reload().await?;
|
||||
}
|
||||
|
||||
let diffs = self.state.room_linked_chunk.updates_as_vector_diffs();
|
||||
@@ -375,15 +375,15 @@ impl<'a> RoomEventCacheStateLockReadGuard<'a> {
|
||||
&self,
|
||||
room: Room,
|
||||
) -> Result<(Vec<Event>, Receiver<TimelineVectorDiffs>), EventCacheError> {
|
||||
let pinned_event_cache = self.state.pinned_event_cache.get_or_init(|| {
|
||||
PinnedEventCache::new(
|
||||
let pinned_events_cache = self.state.pinned_events_cache.get_or_init(|| {
|
||||
PinnedEventsCache::new(
|
||||
room,
|
||||
self.state.linked_chunk_update_sender.clone(),
|
||||
self.state.store.clone(),
|
||||
)
|
||||
});
|
||||
|
||||
pinned_event_cache.subscribe().await
|
||||
pinned_events_cache.subscribe().await
|
||||
}
|
||||
|
||||
/// Get an event-focused cache for this event and thread mode, if it
|
||||
@@ -405,11 +405,11 @@ impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
|
||||
&mut self.state.room_linked_chunk
|
||||
}
|
||||
|
||||
/// Get a reference to the [`pinned_event_cache`] if it has been
|
||||
/// Get a reference to the [`pinned_events_cache`] if it has been
|
||||
/// initialized.
|
||||
#[cfg(any(feature = "e2e-encryption", test))]
|
||||
pub fn pinned_event_cache(&self) -> Option<&PinnedEventCache> {
|
||||
self.state.pinned_event_cache.get()
|
||||
pub fn pinned_events_cache(&self) -> Option<&PinnedEventsCache> {
|
||||
self.state.pinned_events_cache.get()
|
||||
}
|
||||
|
||||
/// Get a reference to all the live [`event_focused_caches`].
|
||||
@@ -741,8 +741,8 @@ impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
|
||||
// below.
|
||||
let state = &mut *self.state;
|
||||
|
||||
if let Some(pinned_event_cache) = state.pinned_event_cache.get_mut() {
|
||||
pinned_event_cache
|
||||
if let Some(pinned_events_cache) = state.pinned_events_cache.get_mut() {
|
||||
pinned_events_cache
|
||||
.maybe_add_live_related_events(&events, &state.room_version_rules.redaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ impl EventCache {
|
||||
let (pinned_cache, ef_caches) = {
|
||||
let mut state = room_cache.state().write().await?;
|
||||
|
||||
let pinned_cache = state.pinned_event_cache().cloned();
|
||||
let pinned_cache = state.pinned_events_cache().cloned();
|
||||
let ef_caches: Vec<_> = state.event_focused_caches().cloned().collect();
|
||||
|
||||
// Consider the room linked chunk.
|
||||
|
||||
@@ -191,7 +191,7 @@ async fn test_pinned_events_are_loaded_from_network_then_are_reloaded_from_stora
|
||||
// Get the room event cache and subscribe to pinned events.
|
||||
let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap();
|
||||
|
||||
// Subscribe to pinned events - this triggers PinnedEventCache::new() which
|
||||
// Subscribe to pinned events - this triggers PinnedEventsCache::new() which
|
||||
// spawns a task that calls reload_from_storage() first.
|
||||
let (events, mut subscriber) = room_event_cache.subscribe_to_pinned_events().await.unwrap();
|
||||
let mut events = events.into();
|
||||
@@ -237,7 +237,7 @@ async fn test_pinned_events_are_loaded_from_network_then_are_reloaded_from_stora
|
||||
// Get the room event cache and subscribe to pinned events.
|
||||
let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap();
|
||||
|
||||
// Subscribe to pinned events - this triggers PinnedEventCache::new() which
|
||||
// Subscribe to pinned events - this triggers PinnedEventsCache::new() which
|
||||
// spawns a task that calls reload_from_storage() first.
|
||||
let (events, mut subscriber) = room_event_cache.subscribe_to_pinned_events().await.unwrap();
|
||||
let mut events = events.into();
|
||||
@@ -313,7 +313,7 @@ async fn test_pinned_events_are_reloaded_from_storage_from_many_chunks() {
|
||||
// Get the room event cache and subscribe to pinned events.
|
||||
let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap();
|
||||
|
||||
// Subscribe to pinned events - this triggers PinnedEventCache::new() which
|
||||
// Subscribe to pinned events - this triggers PinnedEventsCache::new() which
|
||||
// spawns a task that calls reload_from_storage() first.
|
||||
let (events, mut subscriber) = room_event_cache.subscribe_to_pinned_events().await.unwrap();
|
||||
let mut events = events.into();
|
||||
@@ -389,7 +389,7 @@ async fn test_pinned_events_dont_include_thread_responses() {
|
||||
// Get the room event cache and subscribe to pinned events.
|
||||
let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap();
|
||||
|
||||
// Subscribe to pinned events - this triggers PinnedEventCache::new() which
|
||||
// Subscribe to pinned events - this triggers PinnedEventsCache::new() which
|
||||
// spawns a task that calls reload_from_storage() first.
|
||||
let (events, mut subscriber) = room_event_cache.subscribe_to_pinned_events().await.unwrap();
|
||||
let mut events = events.into();
|
||||
|
||||
Reference in New Issue
Block a user