Skip to content

Commit 50be8a1

Browse files
committed
refactor(event cache): only send a thread summary update when a thread has changed
1 parent aa29107 commit 50be8a1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

crates/matrix-sdk-common/src/deserialized_responses.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'de> Deserialize<'de> for EncryptionInfo {
370370
/// - the number of replies to the thread,
371371
/// - the full event of the latest reply to the thread,
372372
/// - whether the user participated or not to this thread.
373-
#[derive(Clone, Debug, Serialize, Deserialize)]
373+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
374374
pub struct ThreadSummary {
375375
/// The number of replies to the thread.
376376
///
@@ -381,7 +381,7 @@ pub struct ThreadSummary {
381381
}
382382

383383
/// The status of a thread summary.
384-
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
384+
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
385385
pub enum ThreadSummaryStatus {
386386
/// We don't know if the event has a thread summary.
387387
#[default]

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,17 @@ mod private {
12241224
related_thread_events.len()
12251225
};
12261226

1227-
target_event.thread_summary = ThreadSummaryStatus::Some(ThreadSummary { num_replies });
1227+
let new_summary = ThreadSummary { num_replies };
12281228

1229+
if let ThreadSummaryStatus::Some(existing) = &target_event.thread_summary {
1230+
if existing == &new_summary {
1231+
trace!("thread summary is already up-to-date");
1232+
return Ok(());
1233+
}
1234+
}
1235+
1236+
// Cause an update to observers.
1237+
target_event.thread_summary = ThreadSummaryStatus::Some(new_summary);
12291238
self.replace_event_at(location, target_event).await?;
12301239

12311240
Ok(())

0 commit comments

Comments
 (0)