Skip to content

Commit b188a15

Browse files
committed
refactor(event cache): inline most uses of EventLinkedChunk::push_events
The only remaining uses outside the `EventLinkedChunk` are in tests of deduplication, so keep the method as a test-only method for now.
1 parent 9ccbac0 commit b188a15

File tree

1 file changed

+13
-33
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+13
-33
lines changed

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

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ impl EventLinkedChunk {
8686
/// Push events after all events or gaps.
8787
///
8888
/// The last event in `events` is the most recent one.
89-
pub fn push_events<I>(&mut self, events: I)
89+
#[cfg(test)]
90+
pub(in crate::event_cache) fn push_events<I>(&mut self, events: I)
9091
where
9192
I: IntoIterator<Item = Event>,
9293
I::IntoIter: ExactSizeIterator,
@@ -298,7 +299,7 @@ impl EventLinkedChunk {
298299
}
299300
}
300301

301-
self.push_events(events.to_vec());
302+
self.chunks.push_items_back(events.to_vec());
302303
}
303304

304305
/// Finish a network back-pagination for this linked chunk by updating the
@@ -348,7 +349,7 @@ impl EventLinkedChunk {
348349
// No prior gap, and no prior events: push the events.
349350
trace!("pushing events received from back-pagination");
350351

351-
self.push_events(events.to_vec());
352+
self.chunks.push_items_back(events.to_vec());
352353

353354
// A new gap may be inserted before the new events, if there are any.
354355
self.events().next().map(|(item_pos, _)| item_pos)
@@ -547,27 +548,6 @@ mod tests {
547548
assert_eq!(linked_chunk.events().count(), 0);
548549
}
549550

550-
#[test]
551-
fn test_push_events() {
552-
let (event_id_0, event_0) = new_event("$ev0");
553-
let (event_id_1, event_1) = new_event("$ev1");
554-
let (event_id_2, event_2) = new_event("$ev2");
555-
556-
let mut linked_chunk = EventLinkedChunk::new();
557-
558-
linked_chunk.push_events([event_0, event_1]);
559-
linked_chunk.push_events([event_2]);
560-
561-
assert_events_eq!(
562-
linked_chunk.events(),
563-
[
564-
(event_id_0 at (0, 0)),
565-
(event_id_1 at (0, 1)),
566-
(event_id_2 at (0, 2)),
567-
]
568-
);
569-
}
570-
571551
#[test]
572552
fn test_replace_gap_at() {
573553
let (event_id_0, event_0) = new_event("$ev0");
@@ -576,7 +556,7 @@ mod tests {
576556

577557
let mut linked_chunk = EventLinkedChunk::new();
578558

579-
linked_chunk.push_events([event_0]);
559+
linked_chunk.chunks.push_items_back([event_0]);
580560
linked_chunk.chunks.push_gap_back(Gap { prev_token: "hello".to_owned() });
581561

582562
let gap_chunk_id = linked_chunk
@@ -616,9 +596,9 @@ mod tests {
616596

617597
let mut linked_chunk = EventLinkedChunk::new();
618598

619-
linked_chunk.push_events([event_0, event_1]);
599+
linked_chunk.chunks.push_items_back([event_0, event_1]);
620600
linked_chunk.chunks.push_gap_back(Gap { prev_token: "middle".to_owned() });
621-
linked_chunk.push_events([event_2]);
601+
linked_chunk.chunks.push_items_back([event_2]);
622602
linked_chunk.chunks.push_gap_back(Gap { prev_token: "end".to_owned() });
623603

624604
// Remove the first gap.
@@ -651,9 +631,9 @@ mod tests {
651631

652632
// Push some events.
653633
let mut linked_chunk = EventLinkedChunk::new();
654-
linked_chunk.push_events([event_0, event_1]);
634+
linked_chunk.chunks.push_items_back([event_0, event_1]);
655635
linked_chunk.chunks.push_gap_back(Gap { prev_token: "hello".to_owned() });
656-
linked_chunk.push_events([event_2, event_3]);
636+
linked_chunk.chunks.push_items_back([event_2, event_3]);
657637

658638
assert_events_eq!(
659639
linked_chunk.events(),
@@ -724,9 +704,9 @@ mod tests {
724704

725705
// Push some events.
726706
let mut linked_chunk = EventLinkedChunk::new();
727-
linked_chunk.push_events([event_0, event_1]);
707+
linked_chunk.chunks.push_items_back([event_0, event_1]);
728708
linked_chunk.chunks.push_gap_back(Gap { prev_token: "raclette".to_owned() });
729-
linked_chunk.push_events([event_2]);
709+
linked_chunk.chunks.push_items_back([event_2]);
730710

731711
// Read the updates as `VectorDiff`.
732712
let diffs = linked_chunk.updates_as_vector_diffs();
@@ -751,7 +731,7 @@ mod tests {
751731

752732
// Now we can reset and see what happens.
753733
linked_chunk.reset();
754-
linked_chunk.push_events([event_3]);
734+
linked_chunk.chunks.push_items_back([event_3]);
755735

756736
// Read the updates as `VectorDiff`.
757737
let diffs = linked_chunk.updates_as_vector_diffs();
@@ -773,7 +753,7 @@ mod tests {
773753
let event_factory = EventFactory::new().room(&DEFAULT_TEST_ROOM_ID).sender(*ALICE);
774754

775755
let mut linked_chunk = EventLinkedChunk::new();
776-
linked_chunk.push_events(vec![
756+
linked_chunk.chunks.push_items_back(vec![
777757
event_factory
778758
.text_msg("hey")
779759
.event_id(event_id!("$123456789101112131415617181920"))

0 commit comments

Comments
 (0)