From 2da0684e95291293d6f4e7e5080b1ce7aaa782c1 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 24 Mar 2022 16:29:08 -0400 Subject: [PATCH] Removing check_only --- crates/utils/src/rate_limit/mod.rs | 5 ----- crates/utils/src/rate_limit/rate_limiter.rs | 7 ++----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/utils/src/rate_limit/mod.rs b/crates/utils/src/rate_limit/mod.rs index 55a1ae8a0..e2a155eb5 100644 --- a/crates/utils/src/rate_limit/mod.rs +++ b/crates/utils/src/rate_limit/mod.rs @@ -86,7 +86,6 @@ impl RateLimited { &ip_addr, rate_limit.message, rate_limit.message_per_second, - false, )?; drop(limiter); @@ -98,7 +97,6 @@ impl RateLimited { &ip_addr, rate_limit.post, rate_limit.post_per_second, - false, )?; } RateLimitType::Register => { @@ -107,7 +105,6 @@ impl RateLimited { &ip_addr, rate_limit.register, rate_limit.register_per_second, - false, )?; } RateLimitType::Image => { @@ -116,7 +113,6 @@ impl RateLimited { &ip_addr, rate_limit.image, rate_limit.image_per_second, - false, )?; } RateLimitType::Comment => { @@ -125,7 +121,6 @@ impl RateLimited { &ip_addr, rate_limit.comment, rate_limit.comment_per_second, - false, )?; } }; diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index de5557ea8..ccc483ed7 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -53,7 +53,6 @@ impl RateLimiter { ip: &IpAddr, rate: i32, per: i32, - check_only: bool, ) -> Result<(), LemmyError> { self.insert_ip(ip); if let Some(bucket) = self.buckets.get_mut(&type_) { @@ -68,7 +67,7 @@ impl RateLimiter { rate_limit.last_checked = current; rate_limit.allowance += time_passed * (rate as f64 / per as f64); - if !check_only && rate_limit.allowance > rate as f64 { + if rate_limit.allowance > rate as f64 { rate_limit.allowance = rate as f64; } @@ -91,9 +90,7 @@ impl RateLimiter { "too_many_requests", )) } else { - if !check_only { - rate_limit.allowance -= 1.0; - } + rate_limit.allowance -= 1.0; Ok(()) } } else {