Skip to content

Commit f1df992

Browse files
committed
feat(redecryptor): More precise logs for the redecryption attempts
1 parent e4e3d33 commit f1df992

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

crates/matrix-sdk/src/event_cache/redecryptor.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ impl EventCache {
229229
room_id: &RoomId,
230230
events: Vec<(OwnedEventId, DecryptedRoomEvent, Option<Vec<Action>>)>,
231231
) -> Result<(), EventCacheError> {
232+
if events.is_empty() {
233+
trace!("No events were redecrypted or updated, nothing to replace");
234+
return Ok(());
235+
}
236+
232237
// Get the cache for this particular room and lock the state for the duration of
233238
// the decryption.
234239
let (room_cache, _drop_handles) = self.for_room(room_id).await?;
@@ -237,7 +242,6 @@ impl EventCache {
237242
let event_ids: BTreeSet<_> =
238243
events.iter().cloned().map(|(event_id, _, _)| event_id).collect();
239244

240-
trace!(?event_ids, "Replacing successfully re-decrypted events");
241245

242246
for (event_id, decrypted, actions) in events {
243247
// The event isn't in the cache, nothing to replace. Realistically this can't
@@ -330,7 +334,7 @@ impl EventCache {
330334

331335
/// Attempt to redecrypt events after a room key with the given session ID
332336
/// has been received.
333-
#[instrument(skip_all, fields(room_key_info))]
337+
#[instrument(skip_all, fields(room_id, session_id))]
334338
async fn retry_decryption(
335339
&self,
336340
room_id: &RoomId,
@@ -364,13 +368,21 @@ impl EventCache {
364368
}
365369
}
366370

371+
let event_ids: BTreeSet<_> =
372+
decrypted_events.iter().map(|(event_id, _, _)| event_id).collect();
373+
374+
if !event_ids.is_empty() {
375+
trace!(?event_ids, "Successfully redecrypted events");
376+
}
377+
367378
// Replace the events and notify listeners that UTDs have been replaced with
368379
// decrypted events.
369380
self.on_resolved_utds(room_id, decrypted_events).await?;
370381

371382
Ok(())
372383
}
373384

385+
#[instrument(skip_all, fields(room_id, session_id))]
374386
async fn update_encryption_info(
375387
&self,
376388
room_id: &RoomId,
@@ -403,6 +415,13 @@ impl EventCache {
403415
}
404416
}
405417

418+
let event_ids: BTreeSet<_> =
419+
updated_events.iter().map(|(event_id, _, _)| event_id).collect();
420+
421+
if !event_ids.is_empty() {
422+
trace!(?event_ids, "Replacing the encryption info of some events");
423+
}
424+
406425
self.on_resolved_utds(room_id, updated_events).await?;
407426

408427
Ok(())

0 commit comments

Comments
 (0)