refactor(event cache): clarify warning when a pinned event couldn't be loaded#6405
refactor(event cache): clarify warning when a pinned event couldn't be loaded#6405
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6405 +/- ##
==========================================
+ Coverage 89.85% 89.86% +0.01%
==========================================
Files 378 378
Lines 103384 103389 +5
Branches 103384 103389 +5
==========================================
+ Hits 92893 92911 +18
+ Misses 6928 6907 -21
- Partials 3563 3571 +8 ☔ View full report in Codecov by Sentry. |
Hywan
left a comment
There was a problem hiding this comment.
Good finding, thanks. I am suggesting a way to avoid the double allocation, not tested though.
| // Get rid of error results. | ||
| .flat_map(stream::iter) |
There was a problem hiding this comment.
Good finding. However, we now allocate twice (with collect) instead of once.
We could use StreamExt::inspect() to count the number of pinned events instead of doing this intermediate collect. Something like:
let mut number_of_loaded_events = 0;
let loaded_events: Vec<Event> =
stream::iter(…)
.buffer_unordered(max_concurrent_requests)
.flat_map(stream::iter)
.inspect(|_| number_of_loaded_events += 1)
.flat_map(stream::iter)
.collect();I think that could work.
Thoughts?
There was a problem hiding this comment.
Ah nice, didn't know about that particular StreamExt method, thanks!
…e 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.
23cad1f to
8d2ab5a
Compare
The previous warning could trigger with abnormal numbers, since there could be related events applying to a pinned event, the
loaded_eventslist could be bigger than the list ofpinned_event_ids, due to the eager flattening. This patch makes it display the correct number, by postponing the flattening after the warning.CHANGELOG.mdfiles.