From 59832e6ba2588c5d1ca1138b890f9ce9d290ad46 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Wed, 15 Mar 2023 21:54:58 +0000 Subject: [PATCH] fix(ratelimiter): mutate entry instead of copying --- crates/quark/src/web/ratelimiter.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/quark/src/web/ratelimiter.rs b/crates/quark/src/web/ratelimiter.rs index 0d264c72..70249842 100644 --- a/crates/quark/src/web/ratelimiter.rs +++ b/crates/quark/src/web/ratelimiter.rs @@ -25,7 +25,7 @@ use dashmap::DashMap; use once_cell::sync::Lazy; /// Ratelimit Bucket -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] struct Entry { used: u8, reset: u128, @@ -50,7 +50,7 @@ impl Entry { } /// Deduct one unit from the bucket and save - pub fn deduct(mut self) { + pub fn deduct(&mut self) { let current_time = now().as_millis(); if current_time > self.reset { self.used = 1; @@ -192,7 +192,7 @@ impl Ratelimiter { let key = key.finish(); let limit = resolve_bucket_limit(bucket); - let entry = Entry::from(key); + let mut entry = Entry::from(key); let remaining = entry.get_remaining(limit); if remaining > 0 {