]> Untitled Git - lemmy.git/blobdiff - crates/utils/src/rate_limit/mod.rs
Moving settings and secrets to context.
[lemmy.git] / crates / utils / src / rate_limit / mod.rs
index ca7f124cd0ab11880efe33f786a9032559e911be..c1a4627c1d9f8ca50913d00ce67f08b90e7b55ec 100644 (file)
@@ -1,9 +1,4 @@
-use crate::{
-  settings::structs::{RateLimitConfig, Settings},
-  utils::get_ip,
-  IpAddr,
-  LemmyError,
-};
+use crate::{settings::structs::RateLimitConfig, utils::get_ip, IpAddr, LemmyError};
 use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
 use futures::future::{ok, Ready};
 use rate_limiter::{RateLimitType, RateLimiter};
@@ -22,11 +17,13 @@ pub struct RateLimit {
   // it might be reasonable to use a std::sync::Mutex here, since we don't need to lock this
   // across await points
   pub rate_limiter: Arc<Mutex<RateLimiter>>,
+  pub rate_limit_config: RateLimitConfig,
 }
 
 #[derive(Debug, Clone)]
 pub struct RateLimited {
   rate_limiter: Arc<Mutex<RateLimiter>>,
+  rate_limit_config: RateLimitConfig,
   type_: RateLimitType,
 }
 
@@ -55,6 +52,7 @@ impl RateLimit {
   fn kind(&self, type_: RateLimitType) -> RateLimited {
     RateLimited {
       rate_limiter: self.rate_limiter.clone(),
+      rate_limit_config: self.rate_limit_config.clone(),
       type_,
     }
   }
@@ -71,7 +69,7 @@ impl RateLimited {
   {
     // Does not need to be blocking because the RwLock in settings never held across await points,
     // and the operation here locks only long enough to clone
-    let rate_limit: RateLimitConfig = Settings::get().rate_limit.unwrap_or_default();
+    let rate_limit = self.rate_limit_config;
 
     // before
     {