From e2709f69673443f034d30c1040073b92dfd0aed3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 3 Dec 2021 22:08:07 -0500 Subject: [PATCH] Moving retry_limit to settings --- config/defaults.hjson | 2 ++ crates/apub/src/fetcher/webfinger.rs | 4 ++-- crates/apub_lib/src/object_id.rs | 4 ++-- crates/utils/src/request.rs | 4 ---- crates/utils/src/settings/structs.rs | 3 +++ 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config/defaults.hjson b/config/defaults.hjson index 003adf11a..14c1dce0b 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -111,4 +111,6 @@ slur_filter: "(\bThis\b)|(\bis\b)|(\bsample\b)" # Maximum length of local community and user names actor_name_max_length: 20 + # Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search). + http_fetch_retry_limit: 25 } diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 3720ec4ef..b44030b06 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -7,7 +7,7 @@ use lemmy_apub_lib::{ }; use lemmy_db_schema::newtypes::DbUrl; use lemmy_utils::{ - request::{retry, RecvError, RETRY_LIMIT}, + request::{retry, RecvError}, LemmyError, }; use lemmy_websocket::LemmyContext; @@ -82,7 +82,7 @@ where debug!("Fetching webfinger url: {}", &fetch_url); *request_counter += 1; - if *request_counter > RETRY_LIMIT { + if *request_counter > context.settings().http_fetch_retry_limit { return Err(LemmyError::from(anyhow!("Request retry limit reached"))); } diff --git a/crates/apub_lib/src/object_id.rs b/crates/apub_lib/src/object_id.rs index 864df454b..e8d0bd6d2 100644 --- a/crates/apub_lib/src/object_id.rs +++ b/crates/apub_lib/src/object_id.rs @@ -3,7 +3,7 @@ use activitystreams::chrono::{Duration as ChronoDuration, NaiveDateTime, Utc}; use anyhow::anyhow; use diesel::NotFound; use lemmy_utils::{ - request::{build_user_agent, retry, RETRY_LIMIT}, + request::{build_user_agent, retry}, settings::structs::Settings, LemmyError, }; @@ -115,7 +115,7 @@ where info!("Fetching remote object {}", self.to_string()); *request_counter += 1; - if *request_counter > RETRY_LIMIT { + if *request_counter > Settings::get().http_fetch_retry_limit { return Err(LemmyError::from(anyhow!("Request retry limit reached"))); } diff --git a/crates/utils/src/request.rs b/crates/utils/src/request.rs index 15d91daa0..88680c080 100644 --- a/crates/utils/src/request.rs +++ b/crates/utils/src/request.rs @@ -17,10 +17,6 @@ struct SendError(pub String); #[error("Error receiving response, {0}")] pub struct RecvError(pub String); -/// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object -/// fetch through the search). This should be configurable. -pub static RETRY_LIMIT: i32 = 25; - pub async fn retry(f: F) -> Result where F: Fn() -> Fut, diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 1b8ac812e..6a20386e7 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -46,6 +46,9 @@ pub struct Settings { /// Maximum length of local community and user names #[default(20)] pub actor_name_max_length: usize, + /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search). + #[default(25)] + pub http_fetch_retry_limit: i32, } #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]