From e9d31687f92fc6a37ed804b709141ca8a60d66e5 Mon Sep 17 00:00:00 2001 From: naskya Date: Thu, 6 Jun 2024 17:10:38 +0900 Subject: [PATCH] chore (backend-rs): remove unused derive --- packages/backend-rs/src/config/server.rs | 22 +++++++------- packages/backend-rs/src/federation/acct.rs | 2 +- .../src/federation/nodeinfo/fetch.rs | 4 +-- .../src/federation/nodeinfo/schema.rs | 30 ++++++++++++------- .../backend-rs/src/misc/get_image_size.rs | 2 +- .../backend-rs/src/misc/get_note_summary.rs | 2 +- packages/backend-rs/src/misc/reaction.rs | 2 +- .../src/service/antenna/process_new_note.rs | 5 ++-- 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/packages/backend-rs/src/config/server.rs b/packages/backend-rs/src/config/server.rs index 93169fe14c..101c860599 100644 --- a/packages/backend-rs/src/config/server.rs +++ b/packages/backend-rs/src/config/server.rs @@ -7,7 +7,7 @@ use std::fs; pub const VERSION: &str = macro_rs::read_version_from_package_json!(); -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] struct ServerConfig { @@ -72,7 +72,7 @@ struct ServerConfig { pub object_storage: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct DbConfig { @@ -85,7 +85,7 @@ pub struct DbConfig { pub extra: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct RedisConfig { @@ -100,7 +100,7 @@ pub struct RedisConfig { pub prefix: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct TlsConfig { @@ -114,7 +114,7 @@ pub struct WorkerConfig { pub queue: u32, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct WorkerConfigInternal { @@ -122,7 +122,7 @@ pub struct WorkerConfigInternal { pub queue: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct IdConfig { @@ -130,7 +130,7 @@ pub struct IdConfig { pub fingerprint: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct SysLogConfig { @@ -138,7 +138,7 @@ pub struct SysLogConfig { pub port: u16, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct DeepLConfig { @@ -147,7 +147,7 @@ pub struct DeepLConfig { pub is_pro: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct LibreTranslateConfig { @@ -156,7 +156,7 @@ pub struct LibreTranslateConfig { pub api_key: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct EmailConfig { @@ -169,7 +169,7 @@ pub struct EmailConfig { pub use_implicit_ssl_tls: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, use_nullable = false)] pub struct ObjectStorageConfig { diff --git a/packages/backend-rs/src/federation/acct.rs b/packages/backend-rs/src/federation/acct.rs index 21e067c04e..b7b44356e6 100644 --- a/packages/backend-rs/src/federation/acct.rs +++ b/packages/backend-rs/src/federation/acct.rs @@ -1,7 +1,7 @@ use std::fmt; use std::str::FromStr; -#[derive(Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] #[crate::export(object)] pub struct Acct { pub username: String, diff --git a/packages/backend-rs/src/federation/nodeinfo/fetch.rs b/packages/backend-rs/src/federation/nodeinfo/fetch.rs index 7c0058b92b..0147830815 100644 --- a/packages/backend-rs/src/federation/nodeinfo/fetch.rs +++ b/packages/backend-rs/src/federation/nodeinfo/fetch.rs @@ -25,13 +25,13 @@ pub enum Error { } /// Represents the schema of `/.well-known/nodeinfo`. -#[derive(Deserialize, Debug)] +#[derive(Deserialize)] pub struct NodeinfoLinks { links: Vec, } /// Represents one entry of `/.well-known/nodeinfo`. -#[derive(Deserialize, Debug)] +#[derive(Deserialize)] pub struct NodeinfoLink { rel: String, href: String, diff --git a/packages/backend-rs/src/federation/nodeinfo/schema.rs b/packages/backend-rs/src/federation/nodeinfo/schema.rs index abbe336723..2876afbbdb 100644 --- a/packages/backend-rs/src/federation/nodeinfo/schema.rs +++ b/packages/backend-rs/src/federation/nodeinfo/schema.rs @@ -10,7 +10,8 @@ use std::collections::HashMap; // * #[serde(tag = "version", rename = "2.1")] (https://github.com/3Hren/msgpack-rust/issues/318) /// NodeInfo schema version 2.1. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Nodeinfo21 { /// The schema version, must be 2.1. @@ -30,7 +31,8 @@ pub struct Nodeinfo21 { } /// NodeInfo schema version 2.0. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[crate::export(object, js_name = "Nodeinfo")] pub struct Nodeinfo20 { @@ -51,7 +53,8 @@ pub struct Nodeinfo20 { } /// Metadata about server software in use (version 2.1). -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Software21 { /// The canonical name of this server software. @@ -65,7 +68,8 @@ pub struct Software21 { } /// Metadata about server software in use (version 2.0). -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[crate::export(object)] pub struct Software20 { @@ -75,7 +79,8 @@ pub struct Software20 { pub version: String, } -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "lowercase")] #[crate::export(string_enum = "lowercase")] pub enum Protocol { @@ -92,7 +97,8 @@ pub enum Protocol { } /// The third party sites this server can connect to via their application API. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[crate::export(object)] pub struct Services { @@ -103,7 +109,8 @@ pub struct Services { } /// The third party sites this server can retrieve messages from for combined display with regular traffic. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "lowercase")] #[crate::export(string_enum = "lowercase")] pub enum Inbound { @@ -121,7 +128,8 @@ pub enum Inbound { } /// The third party sites this server can publish messages to on the behalf of a user. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "lowercase")] #[crate::export(string_enum = "lowercase")] pub enum Outbound { @@ -158,7 +166,8 @@ pub enum Outbound { } /// Usage statistics for this server. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[crate::export(object)] pub struct Usage { @@ -168,7 +177,8 @@ pub struct Usage { } /// statistics about the users of this server. -#[derive(Deserialize, Serialize, Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[crate::export(object)] pub struct Users { diff --git a/packages/backend-rs/src/misc/get_image_size.rs b/packages/backend-rs/src/misc/get_image_size.rs index c1348e62c3..5fc068fbe0 100644 --- a/packages/backend-rs/src/misc/get_image_size.rs +++ b/packages/backend-rs/src/misc/get_image_size.rs @@ -41,7 +41,7 @@ const BROWSER_SAFE_IMAGE_TYPES: [ImageFormat; 8] = [ static MTX_GUARD: Mutex<()> = Mutex::const_new(()); -#[derive(Debug, PartialEq)] +#[cfg_attr(test, derive(Debug, PartialEq))] #[crate::export(object)] pub struct ImageSize { pub width: u32, diff --git a/packages/backend-rs/src/misc/get_note_summary.rs b/packages/backend-rs/src/misc/get_note_summary.rs index ab2cc88713..f2bfcd2470 100644 --- a/packages/backend-rs/src/misc/get_note_summary.rs +++ b/packages/backend-rs/src/misc/get_note_summary.rs @@ -1,6 +1,6 @@ use serde::Deserialize; -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] #[crate::export(object)] pub struct PartialNoteToSummarize { diff --git a/packages/backend-rs/src/misc/reaction.rs b/packages/backend-rs/src/misc/reaction.rs index 8e9800a166..50b679cd53 100644 --- a/packages/backend-rs/src/misc/reaction.rs +++ b/packages/backend-rs/src/misc/reaction.rs @@ -6,7 +6,7 @@ use regex::Regex; use sea_orm::prelude::*; use std::collections::HashMap; -#[derive(PartialEq, Debug)] +#[cfg_attr(test, derive(PartialEq, Debug))] #[crate::export(object)] pub struct DecodedReaction { pub reaction: String, diff --git a/packages/backend-rs/src/service/antenna/process_new_note.rs b/packages/backend-rs/src/service/antenna/process_new_note.rs index d28af982b6..a4fdc28848 100644 --- a/packages/backend-rs/src/service/antenna/process_new_note.rs +++ b/packages/backend-rs/src/service/antenna/process_new_note.rs @@ -28,15 +28,14 @@ pub enum Error { // for napi export // https://github.com/napi-rs/napi-rs/issues/2060 -type Antenna = antenna::Model; type Note = note::Model; // TODO?: it might be better to store this directly in memory // (like fetch_meta) instead of Redis as it's used so much -async fn antennas() -> Result, Error> { +async fn antennas() -> Result, Error> { const CACHE_KEY: &str = "antennas"; - if let Some(antennas) = cache::get::>(CACHE_KEY).await? { + if let Some(antennas) = cache::get::>(CACHE_KEY).await? { Ok(antennas) } else { let antennas = antenna::Entity::find().all(db_conn().await?).await?;