Skip to content

Commit

Permalink
refactor(sdk): Rename deduplicated_all_new_events.
Browse files Browse the repository at this point in the history
This patch renames `deduplicated_all_new_events` to
`has_zero_new_unique_events` as I believe it removes an ambiguity around
the naming: “all new events have been duplicated, whatever the resulting
number of unique events” vs. “all new events were duplicated, there is no
unique event”. The new method name takes a different angle by expressing
a question rather than a state.
  • Loading branch information
Hywan committed Jan 8, 2025
1 parent e7d51a0 commit 5347af9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/matrix-sdk/src/event_cache/room/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl RoomEvents {
let (events, duplicated_event_ids) =
self.collect_valid_and_duplicated_events(events.into_iter());

if deduplicated_all_new_events(events.len(), duplicated_event_ids.len()) {
if has_zero_new_unique_events(events.len(), duplicated_event_ids.len()) {
return false;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ impl RoomEvents {
let (events, duplicated_event_ids) =
self.collect_valid_and_duplicated_events(events.into_iter());

if deduplicated_all_new_events(events.len(), duplicated_event_ids.len()) {
if has_zero_new_unique_events(events.len(), duplicated_event_ids.len()) {
return Ok(false);
}

Expand Down Expand Up @@ -174,7 +174,7 @@ impl RoomEvents {
let (events, duplicated_event_ids) =
self.collect_valid_and_duplicated_events(events.into_iter());

if deduplicated_all_new_events(events.len(), duplicated_event_ids.len()) {
if has_zero_new_unique_events(events.len(), duplicated_event_ids.len()) {
let pos = self.chunks.remove_gap_at(gap_identifier)?;
return Ok((false, pos));
}
Expand Down Expand Up @@ -326,8 +326,12 @@ impl RoomEvents {
/// already seen, and possibly misplace them. And we should not be missing
/// events either: the already-known events would have their own previous-batch
/// token (it might already be consumed).
fn deduplicated_all_new_events(num_new_unique: usize, num_duplicated: usize) -> bool {
num_new_unique > 0 && num_new_unique == num_duplicated
#[inline]
fn has_zero_new_unique_events(
number_of_new_events: usize,
number_of_duplicated_events: usize,
) -> bool {
number_of_new_events > 0 && number_of_new_events == number_of_duplicated_events
}

// Private implementations, implementation specific.
Expand Down

0 comments on commit 5347af9

Please sign in to comment.