Skip to content

Commit 2266d0d

Browse files
committed
chore: Performance improvement on read receipts.
1 parent 06c981a commit 2266d0d

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

crates/matrix-sdk-ui/src/timeline/controller/read_receipts.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -288,33 +288,6 @@ impl ReadReceipts {
288288
timeline_items: &mut ObservableItemsTransaction<'_>,
289289
at_end: bool,
290290
) -> IndexMap<OwnedUserId, Receipt> {
291-
// We only need to compute receipts for the visible events that will show them.
292-
if !timeline_items
293-
.all_remote_events()
294-
.iter()
295-
.find(|meta| meta.event_id == event_id)
296-
.map(|meta| meta.visible && meta.can_show_read_receipts)
297-
.unwrap_or(false)
298-
{
299-
return Default::default();
300-
}
301-
302-
let mut all_receipts = self.get_event_receipts(event_id).cloned().unwrap_or_default();
303-
304-
if at_end {
305-
// No need to search for extra receipts, there are no events after.
306-
trace!(
307-
"early return because @end, retrieved receipts: {}",
308-
all_receipts.iter().map(|(u, _)| u.as_str()).collect::<Vec<_>>().join(", ")
309-
);
310-
return all_receipts;
311-
}
312-
313-
trace!(
314-
"loaded receipts: {}",
315-
all_receipts.iter().map(|(u, _)| u.as_str()).collect::<Vec<_>>().join(", ")
316-
);
317-
318291
// We are going to add receipts for hidden events to this item.
319292
//
320293
// However: since we may be inserting an event at a random position, the
@@ -330,13 +303,34 @@ impl ReadReceipts {
330303

331304
for meta in events_iter.by_ref() {
332305
if meta.event_id == event_id {
333-
break;
306+
// We only need to compute receipts for the visible events that will show them.
307+
if !meta.visible || !meta.can_show_read_receipts {
308+
return Default::default();
309+
} else {
310+
break;
311+
}
334312
}
335313
if let Some(item_index) = meta.timeline_item_index {
336314
prev_event_and_item_index = Some((meta.event_id.clone(), item_index));
337315
}
338316
}
339317

318+
let mut all_receipts = self.get_event_receipts(event_id).cloned().unwrap_or_default();
319+
320+
if at_end {
321+
// No need to search for extra receipts, there are no events after.
322+
trace!(
323+
"early return because @end, retrieved receipts: {}",
324+
all_receipts.iter().map(|(u, _)| u.as_str()).collect::<Vec<_>>().join(", ")
325+
);
326+
return all_receipts;
327+
}
328+
329+
trace!(
330+
"loaded receipts: {}",
331+
all_receipts.iter().map(|(u, _)| u.as_str()).collect::<Vec<_>>().join(", ")
332+
);
333+
340334
// Include receipts from all the following events that are hidden or can't show
341335
// read receipts.
342336
let mut hidden = Vec::new();

0 commit comments

Comments
 (0)