fix(ratelimiter): mutate entry instead of copying

This commit is contained in:
Paul Makles
2023-03-15 21:54:58 +00:00
parent f309218573
commit 59832e6ba2

View File

@@ -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 {