Skip to content

Commit 5e927f8

Browse files
committed
refactor(sdk): Rename RoomEventCache::event to RoomEventCache::find_event.
This patch renames the `RoomEventCache::event` method to `find_event` to clarify what it does, and to match the Rust standard library namings.
1 parent f91ee36 commit 5e927f8

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ async fn test_cached_events_are_kept_for_different_room_instances() {
255255
assert!(!items.is_empty()); // We just loaded some events
256256
assert_pending!(timeline_stream);
257257

258-
assert!(room_cache.event(event_id!("$1")).await.is_some());
258+
assert!(room_cache.find_event(event_id!("$1")).await.is_some());
259259

260260
// Drop the existing room and timeline instances
261261
drop(timeline_stream);
@@ -276,7 +276,7 @@ async fn test_cached_events_are_kept_for_different_room_instances() {
276276

277277
let (items, _) = timeline.subscribe().await;
278278
assert!(!items.is_empty()); // These events came from the cache
279-
assert!(room_cache.event(event_id!("$1")).await.is_some());
279+
assert!(room_cache.find_event(event_id!("$1")).await.is_some());
280280

281281
// Drop the existing room and timeline instances
282282
server.server().reset().await;
@@ -401,7 +401,7 @@ async fn test_pinned_timeline_with_no_pinned_events_on_pagination_is_just_empty(
401401
.expect("Pagination of events should successful");
402402

403403
// Assert the event is loaded and added to the cache
404-
assert!(event_cache.event(event_id).await.is_some());
404+
assert!(event_cache.find_event(event_id).await.is_some());
405405

406406
// And it won't cause an update in the pinned events timeline since it's not
407407
// pinned

crates/matrix-sdk/src/event_cache/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,15 +828,15 @@ mod tests {
828828

829829
let (room_event_cache, _drop_handles) = room1.event_cache().await.unwrap();
830830

831-
let found1 = room_event_cache.event(eid1).await.unwrap();
831+
let found1 = room_event_cache.find_event(eid1).await.unwrap();
832832
assert_event_matches_msg(&found1, "hey");
833833

834-
let found2 = room_event_cache.event(eid2).await.unwrap();
834+
let found2 = room_event_cache.find_event(eid2).await.unwrap();
835835
assert_event_matches_msg(&found2, "you");
836836

837837
// Retrieving the event with id3 from the room which doesn't contain it will
838838
// fail…
839-
assert!(room_event_cache.event(eid3).await.is_none());
839+
assert!(room_event_cache.find_event(eid3).await.is_none());
840840
}
841841

842842
#[async_test]
@@ -857,7 +857,7 @@ mod tests {
857857
room_event_cache.save_events([f.text_msg("hey there").event_id(event_id).into()]).await;
858858

859859
// Retrieving the event at the room-wide cache works.
860-
assert!(room_event_cache.event(event_id).await.is_some());
860+
assert!(room_event_cache.find_event(event_id).await.is_some());
861861
}
862862

863863
#[async_test]

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ impl RoomEventCache {
214214
RoomPagination { inner: self.inner.clone() }
215215
}
216216

217-
/// Try to find an event by id in this room.
218-
pub async fn event(&self, event_id: &EventId) -> Option<Event> {
217+
/// Try to find an event by ID in this room.
218+
///
219+
/// It starts by looking into loaded events before looking inside the
220+
/// storage.
221+
pub async fn find_event(&self, event_id: &EventId) -> Option<Event> {
219222
self.inner
220223
.state
221224
.read()
@@ -2210,8 +2213,8 @@ mod timed_tests {
22102213

22112214
// The rooms knows about all cached events.
22122215
{
2213-
assert!(room_event_cache.event(event_id1).await.is_some());
2214-
assert!(room_event_cache.event(event_id2).await.is_some());
2216+
assert!(room_event_cache.find_event(event_id1).await.is_some());
2217+
assert!(room_event_cache.find_event(event_id2).await.is_some());
22152218
}
22162219

22172220
// But only part of events are loaded from the store
@@ -2251,7 +2254,7 @@ mod timed_tests {
22512254

22522255
// Events individually are not forgotten by the event cache, after clearing a
22532256
// room.
2254-
assert!(room_event_cache.event(event_id1).await.is_some());
2257+
assert!(room_event_cache.find_event(event_id1).await.is_some());
22552258

22562259
// But their presence in a linked chunk is forgotten.
22572260
let items = room_event_cache.events().await;
@@ -2365,8 +2368,8 @@ mod timed_tests {
23652368
assert!(stream.is_empty());
23662369

23672370
// The event cache knows only all events though, even if they aren't loaded.
2368-
assert!(room_event_cache.event(event_id1).await.is_some());
2369-
assert!(room_event_cache.event(event_id2).await.is_some());
2371+
assert!(room_event_cache.find_event(event_id1).await.is_some());
2372+
assert!(room_event_cache.find_event(event_id2).await.is_some());
23702373

23712374
// Let's paginate to load more events.
23722375
room_event_cache.pagination().run_backwards_once(20).await.unwrap();

crates/matrix-sdk/src/room/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ impl Room {
616616
Ok(event)
617617
}
618618

619-
/// Try to load the event from the event cache, if it's enabled, or fetch it
620-
/// from the homeserver.
619+
/// Try to load the event from the [`EventCache`][crate::event_cache], if
620+
/// it's enabled, or fetch it from the homeserver.
621621
///
622622
/// When running the request against the homeserver, it uses the given
623623
/// [`RequestConfig`] if provided, or the client's default one
@@ -629,7 +629,7 @@ impl Room {
629629
) -> Result<TimelineEvent> {
630630
match self.event_cache().await {
631631
Ok((event_cache, _drop_handles)) => {
632-
if let Some(event) = event_cache.event(event_id).await {
632+
if let Some(event) = event_cache.find_event(event_id).await {
633633
return Ok(event);
634634
}
635635
// Fallthrough: try with a request.

crates/matrix-sdk/tests/integration/room/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ async fn test_event() {
655655

656656
// Requested event was saved to the cache
657657
let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap();
658-
assert!(room_event_cache.event(event_id).await.is_some());
658+
assert!(room_event_cache.find_event(event_id).await.is_some());
659659

660660
// So we can reload it without hitting the network.
661661
let timeline_event = room.load_or_fetch_event(event_id, None).await.unwrap();
@@ -728,9 +728,9 @@ async fn test_event_with_context() {
728728

729729
// Requested event and their context ones were saved to the cache
730730
let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap();
731-
assert!(room_event_cache.event(event_id).await.is_some());
732-
assert!(room_event_cache.event(prev_event_id).await.is_some());
733-
assert!(room_event_cache.event(next_event_id).await.is_some());
731+
assert!(room_event_cache.find_event(event_id).await.is_some());
732+
assert!(room_event_cache.find_event(prev_event_id).await.is_some());
733+
assert!(room_event_cache.find_event(next_event_id).await.is_some());
734734
}
735735

736736
#[async_test]

0 commit comments

Comments
 (0)