remove unnecessary tracing of pdu conversions

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-07 04:42:35 +00:00
parent b7a41f283f
commit da984d49cf
3 changed files with 15 additions and 16 deletions

View file

@ -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(

View file

@ -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<AnySyncTimelineEvent> {
let (redacts, content) = self.copy_redacts();
let mut json = json!({
@ -36,8 +36,8 @@ pub fn to_sync_room_event(&self) -> Raw<AnySyncTimelineEvent> {
}
/// 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<AnyEphemeralRoomEvent> {
let (redacts, content) = self.copy_redacts();
let mut json = json!({
@ -62,8 +62,8 @@ pub fn to_any_event(&self) -> Raw<AnyEphemeralRoomEvent> {
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<AnyTimelineEvent> {
let (redacts, content) = self.copy_redacts();
let mut json = json!({
@ -88,8 +88,8 @@ pub fn to_room_event(&self) -> Raw<AnyTimelineEvent> {
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<AnyMessageLikeEvent> {
let (redacts, content) = self.copy_redacts();
let mut json = json!({
@ -114,8 +114,8 @@ pub fn to_message_like_event(&self) -> Raw<AnyMessageLikeEvent> {
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<AnyStateEvent> {
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<AnySyncStateEvent> {
let mut json = json!({
"content": self.content,
@ -159,8 +159,8 @@ pub fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> {
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<AnyStrippedStateEvent> {
let json = json!({
"content": self.content,
@ -172,8 +172,8 @@ pub fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> {
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<HierarchySpaceChildEvent> {
let json = json!({
"content": self.content,
@ -186,8 +186,8 @@ pub fn to_stripped_spacechild_state_event(&self) -> Raw<HierarchySpaceChildEvent
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_member_event(&self) -> Raw<StateEvent<RoomMemberEventContent>> {
let mut json = json!({
"content": self.content,

View file

@ -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"))))?;