Skip to content

Commit 25e4c8d

Browse files
committed
read receipts: add lots of tracing logs for easier remote debugging
1 parent a9d6ab7 commit 25e4c8d

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

crates/matrix-sdk-base/src/read_receipts.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ use ruma::{
136136
EventId, OwnedEventId, OwnedUserId, RoomId, UserId,
137137
};
138138
use serde::{Deserialize, Serialize};
139-
use tracing::{debug, instrument, trace};
139+
use tracing::{debug, instrument, trace, warn};
140140

141141
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
142142
struct LatestReadReceipt {
@@ -332,24 +332,27 @@ impl ReceiptSelector {
332332
if event_pos >= *best_pos {
333333
*best_pos = event_pos;
334334
self.latest_event_with_receipt = Some(event_id.to_owned());
335-
trace!("saving better");
335+
debug!("saving better");
336+
} else {
337+
trace!("not better, keeping previous");
336338
}
337339
} else {
338340
// We didn't have a previous receipt, this is the first one we
339341
// store: remember it.
340342
self.latest_event_pos = Some(event_pos);
341343
self.latest_event_with_receipt = Some(event_id.to_owned());
342-
trace!("saving for the first time");
344+
debug!("saving for the first time");
343345
}
344346
}
345347

346348
/// Try to match pending receipts against new events.
349+
#[instrument(skip_all)]
347350
fn handle_pending_receipts(&mut self, pending: &mut RingBuffer<OwnedEventId>) {
348351
// Try to match stashed receipts against the new events.
349-
trace!("handle_pending_receipts");
350352
pending.retain(|event_id| {
351353
if let Some(event_pos) = self.event_id_to_pos.get(event_id) {
352354
// Maybe select this read receipt as it might be better than the ones we had.
355+
trace!(%event_id, "matching event against its stashed receipt");
353356
self.try_select_later(event_id, *event_pos);
354357

355358
// Remove this stashed read receipt from the pending list, as it's been
@@ -371,23 +374,25 @@ impl ReceiptSelector {
371374
///
372375
/// Returns any receipts (for the current user) that we could not match
373376
/// against any event - these are "pending".
377+
#[instrument(skip_all)]
374378
fn handle_new_receipt(
375379
&mut self,
376380
user_id: &UserId,
377381
receipt_event: &ReceiptEventContent,
378382
) -> Vec<OwnedEventId> {
379-
trace!("handle_new_receipt");
380383
let mut pending = Vec::new();
381384
// Now consider new receipts.
382385
for (event_id, receipts) in &receipt_event.0 {
383386
for ty in [ReceiptType::Read, ReceiptType::ReadPrivate] {
384387
if let Some(receipt) = receipts.get(&ty).and_then(|receipts| receipts.get(user_id))
385388
{
386389
if matches!(receipt.thread, ReceiptThread::Main | ReceiptThread::Unthreaded) {
390+
trace!(%event_id, "found new candidate");
387391
if let Some(event_pos) = self.event_id_to_pos.get(event_id) {
388392
self.try_select_later(event_id, *event_pos);
389393
} else {
390394
// It's a new pending receipt.
395+
trace!(%event_id, "stashed as pending");
391396
pending.push(event_id.clone());
392397
}
393398
}
@@ -502,7 +507,7 @@ pub(crate) fn compute_unread_counts(
502507
// safely from here.
503508
read_receipts.find_and_process_events(&event_id, user_id, all_events.iter());
504509

505-
trace!(?read_receipts, "after finding a better receipt");
510+
debug!(?read_receipts, "after finding a better receipt");
506511
return;
507512
}
508513

@@ -517,15 +522,15 @@ pub(crate) fn compute_unread_counts(
517522
read_receipts.process_event(event, user_id);
518523
}
519524

520-
trace!(?read_receipts, "no better receipt, {} new events", new_events.len());
525+
debug!(?read_receipts, "no better receipt, {} new events", new_events.len());
521526
}
522527

523528
/// Is the event worth marking a room as unread?
524529
fn marks_as_unread(event: &Raw<AnySyncTimelineEvent>, user_id: &UserId) -> bool {
525530
let event = match event.deserialize() {
526531
Ok(event) => event,
527532
Err(err) => {
528-
debug!(
533+
warn!(
529534
"couldn't deserialize event {:?}: {err}",
530535
event.get_field::<String>("event_id").ok().flatten()
531536
);
@@ -601,7 +606,7 @@ fn marks_as_unread(event: &Raw<AnySyncTimelineEvent>, user_id: &UserId) -> bool
601606

602607
_ => {
603608
// What I don't know about, I don't care about.
604-
debug!("unhandled timeline event type: {}", event.event_type());
609+
warn!("unhandled timeline event type: {}", event.event_type());
605610
false
606611
}
607612
}

crates/matrix-sdk-ui/src/timeline/inner/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,11 @@ impl TimelineInner {
10661066
if let Some((old_pub_read, _)) =
10671067
state.user_receipt(own_user_id, ReceiptType::Read, room).await
10681068
{
1069+
trace!(%old_pub_read, "found a previous public receipt");
10691070
if let Some(relative_pos) =
10701071
state.meta.compare_events_positions(&old_pub_read, event_id)
10711072
{
1073+
trace!("event referred to new receipt is {relative_pos:?} the previous receipt");
10721074
return relative_pos == RelativePosition::After;
10731075
}
10741076
}
@@ -1079,9 +1081,11 @@ impl TimelineInner {
10791081
if let Some((old_priv_read, _)) =
10801082
state.latest_user_read_receipt(own_user_id, room).await
10811083
{
1084+
trace!(%old_priv_read, "found a previous private receipt");
10821085
if let Some(relative_pos) =
10831086
state.meta.compare_events_positions(&old_priv_read, event_id)
10841087
{
1088+
trace!("event referred to new receipt is {relative_pos:?} the previous receipt");
10851089
return relative_pos == RelativePosition::After;
10861090
}
10871091
}

crates/matrix-sdk-ui/src/timeline/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use ruma::{
5656
};
5757
use thiserror::Error;
5858
use tokio::sync::{mpsc::Sender, Mutex, Notify};
59-
use tracing::{debug, error, info, instrument, warn};
59+
use tracing::{debug, error, info, instrument, trace, warn};
6060

6161
use self::futures::SendAttachment;
6262

@@ -708,9 +708,13 @@ impl Timeline {
708708
event_id: OwnedEventId,
709709
) -> Result<bool> {
710710
if !self.inner.should_send_receipt(&receipt_type, &thread, &event_id).await {
711+
trace!(
712+
"not sending receipt, because we already cover the event with a previous receipt"
713+
);
711714
return Ok(false);
712715
}
713716

717+
trace!("sending receipt");
714718
self.room().send_single_receipt(receipt_type, thread, event_id).await?;
715719
Ok(true)
716720
}

0 commit comments

Comments
 (0)