forked from jmug/stoatchat
fix(ratelimiter): mutate entry instead of copying
This commit is contained in:
@@ -25,7 +25,7 @@ use dashmap::DashMap;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
/// Ratelimit Bucket
|
/// Ratelimit Bucket
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
struct Entry {
|
struct Entry {
|
||||||
used: u8,
|
used: u8,
|
||||||
reset: u128,
|
reset: u128,
|
||||||
@@ -50,7 +50,7 @@ impl Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deduct one unit from the bucket and save
|
/// Deduct one unit from the bucket and save
|
||||||
pub fn deduct(mut self) {
|
pub fn deduct(&mut self) {
|
||||||
let current_time = now().as_millis();
|
let current_time = now().as_millis();
|
||||||
if current_time > self.reset {
|
if current_time > self.reset {
|
||||||
self.used = 1;
|
self.used = 1;
|
||||||
@@ -192,7 +192,7 @@ impl Ratelimiter {
|
|||||||
|
|
||||||
let key = key.finish();
|
let key = key.finish();
|
||||||
let limit = resolve_bucket_limit(bucket);
|
let limit = resolve_bucket_limit(bucket);
|
||||||
let entry = Entry::from(key);
|
let mut entry = Entry::from(key);
|
||||||
|
|
||||||
let remaining = entry.get_remaining(limit);
|
let remaining = entry.get_remaining(limit);
|
||||||
if remaining > 0 {
|
if remaining > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user