From da984d49cf1b3c4942662d325e04b40d8ef6d932 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 7 Dec 2024 04:42:35 +0000 Subject: [PATCH] remove unnecessary tracing of pdu conversions Signed-off-by: Jason Volk --- src/core/pdu/redact.rs | 7 +++---- src/core/pdu/strip.rs | 22 +++++++++++----------- src/service/rooms/timeline/mod.rs | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/core/pdu/redact.rs b/src/core/pdu/redact.rs index e116e563..01d9147c 100644 --- a/src/core/pdu/redact.rs +++ b/src/core/pdu/redact.rs @@ -11,7 +11,7 @@ use serde_json::{ value::{to_raw_value, RawValue as RawJsonValue}, }; -use crate::{implement, warn, Error, Result}; +use crate::{implement, Error, Result}; #[derive(Deserialize)] struct ExtractRedactedBecause { @@ -19,14 +19,13 @@ struct ExtractRedactedBecause { } #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] -pub fn redact(&mut self, room_version_id: RoomVersionId, reason: &Self) -> Result { +pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: &Self) -> Result { self.unsigned = None; let mut content = serde_json::from_str(self.content.get()).map_err(|_| Error::bad_database("PDU in db has invalid content."))?; - redact_content_in_place(&mut content, &room_version_id, self.kind.to_string()) + redact_content_in_place(&mut content, room_version_id, self.kind.to_string()) .map_err(|e| Error::Redaction(self.sender.server_name().to_owned(), e))?; self.unsigned = Some( diff --git a/src/core/pdu/strip.rs b/src/core/pdu/strip.rs index 30fee863..59457749 100644 --- a/src/core/pdu/strip.rs +++ b/src/core/pdu/strip.rs @@ -8,10 +8,10 @@ use ruma::{ }; use serde_json::{json, value::Value as JsonValue}; -use crate::{implement, warn}; +use crate::implement; +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_sync_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ @@ -36,8 +36,8 @@ pub fn to_sync_room_event(&self) -> Raw { } /// This only works for events that are also AnyRoomEvents. +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_any_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ @@ -62,8 +62,8 @@ pub fn to_any_event(&self) -> Raw { serde_json::from_value(json).expect("Raw::from_value always works") } +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ @@ -88,8 +88,8 @@ pub fn to_room_event(&self) -> Raw { serde_json::from_value(json).expect("Raw::from_value always works") } +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_message_like_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ @@ -114,8 +114,8 @@ pub fn to_message_like_event(&self) -> Raw { serde_json::from_value(json).expect("Raw::from_value always works") } -#[implement(super::Pdu)] #[must_use] +#[implement(super::Pdu)] pub fn to_state_event_value(&self) -> JsonValue { let mut json = json!({ "content": self.content, @@ -134,14 +134,14 @@ pub fn to_state_event_value(&self) -> JsonValue { json } +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_state_event(&self) -> Raw { serde_json::from_value(self.to_state_event_value()).expect("Raw::from_value always works") } +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_sync_state_event(&self) -> Raw { let mut json = json!({ "content": self.content, @@ -159,8 +159,8 @@ pub fn to_sync_state_event(&self) -> Raw { serde_json::from_value(json).expect("Raw::from_value always works") } +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_stripped_state_event(&self) -> Raw { let json = json!({ "content": self.content, @@ -172,8 +172,8 @@ pub fn to_stripped_state_event(&self) -> Raw { serde_json::from_value(json).expect("Raw::from_value always works") } +#[must_use] #[implement(super::Pdu)] -#[tracing::instrument(skip(self), level = "debug")] pub fn to_stripped_spacechild_state_event(&self) -> Raw { let json = json!({ "content": self.content, @@ -186,8 +186,8 @@ pub fn to_stripped_spacechild_state_event(&self) -> Raw Raw> { let mut json = json!({ "content": self.content, diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 0a96322b..b9fcdcd2 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -1024,7 +1024,7 @@ impl Service { let room_version_id = self.services.state.get_room_version(&pdu.room_id).await?; - pdu.redact(room_version_id, reason)?; + pdu.redact(&room_version_id, reason)?; let obj = utils::to_canonical_object(&pdu) .map_err(|e| err!(Database(error!(?event_id, ?e, "Failed to convert PDU to canonical JSON"))))?;