Skip to content

Commit a1157d2

Browse files
committed
refactor(event cache): clarify warning when a pinned event couldn't be loaded
The previous warning could trigger with abnormal numbers, since there could be related events applying to a pinned event, the `loaded_events` list could be bigger than the list of `pinned_event_ids`, due to the eager flattening. This patch makes it display the correct number, by postponing the flattening after the warning.
1 parent fcce02f commit a1157d2

File tree

1 file changed

+12
-3
lines changed
  • crates/matrix-sdk/src/event_cache/caches/pinned_events

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ impl PinnedEventCache {
480480
return Ok(Some(Vec::new()));
481481
}
482482

483+
let mut num_successful_loads = 0;
484+
483485
let mut loaded_events: Vec<Event> =
484486
stream::iter(pinned_event_ids.clone().into_iter().map(|event_id| {
485487
let room = room.clone();
@@ -500,16 +502,23 @@ impl PinnedEventCache {
500502
}
501503
}))
502504
.buffer_unordered(max_concurrent_requests)
503-
// Flatten all the vectors.
505+
// Count successful queries.
506+
.inspect(|result| {
507+
if result.is_ok() {
508+
num_successful_loads += 1;
509+
}
510+
})
511+
// Get rid of error results.
504512
.flat_map(stream::iter)
513+
// Flatten the list of `Vec<Event>` into a list of `Event`.
505514
.flat_map(stream::iter)
506515
.collect()
507516
.await;
508517

509-
if loaded_events.len() != pinned_event_ids.len() {
518+
if num_successful_loads != pinned_event_ids.len() {
510519
warn!(
511520
"only successfully loaded {} out of {} pinned events",
512-
loaded_events.len(),
521+
num_successful_loads,
513522
pinned_event_ids.len()
514523
);
515524
}

0 commit comments

Comments
 (0)