Improve limit check
This commit is contained in:
parent
fec52f506d
commit
d2f3403a18
26
src/limit.rs
26
src/limit.rs
|
@ -100,18 +100,26 @@ impl LimitedRequester {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_send_request(&mut self, limit_type: LimitType) -> bool {
|
fn can_send_request(&mut self, limit_type: LimitType) -> bool {
|
||||||
let limits = self.limits_rate.get(&limit_type);
|
let limits = &self.limits_rate;
|
||||||
|
// Check if all of the limits in this vec have at least one remaining request
|
||||||
match limits {
|
let constant_limits: Vec<&LimitType> = [
|
||||||
Some(limit) => {
|
&LimitType::Error,
|
||||||
if limit.remaining > 0 {
|
&LimitType::Global,
|
||||||
true
|
&LimitType::Ip,
|
||||||
} else {
|
&limit_type,
|
||||||
false
|
]
|
||||||
|
.to_vec();
|
||||||
|
for limit in constant_limits.iter() {
|
||||||
|
match limits.get(&limit) {
|
||||||
|
Some(limit) => {
|
||||||
|
if limit.remaining == 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
None => return false,
|
||||||
}
|
}
|
||||||
None => false,
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_limits(&mut self, response: &Response, limit_type: LimitType) {
|
fn update_limits(&mut self, response: &Response, limit_type: LimitType) {
|
||||||
|
|
Loading…
Reference in New Issue