mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 17:15:35 +00:00
use max items time offset instead of totals count formula
This commit is contained in:
parent
d1d628e878
commit
a087a236b7
1 changed files with 5 additions and 5 deletions
10
src/ban.rs
10
src/ban.rs
|
|
@ -9,14 +9,14 @@ pub struct Item {
|
|||
|
||||
pub struct Ban {
|
||||
index: HashMap<Id20, DateTime<Local>>,
|
||||
timeout: u64,
|
||||
timeout: Duration,
|
||||
}
|
||||
|
||||
impl Ban {
|
||||
pub fn init(timeout: u64, capacity: usize) -> Self {
|
||||
Self {
|
||||
index: HashMap::with_capacity(capacity),
|
||||
timeout,
|
||||
timeout: Duration::from_secs(timeout),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ impl Ban {
|
|||
self.index.len()
|
||||
}
|
||||
|
||||
/// * returns removed `Item` details
|
||||
/// * return removed `Item` details
|
||||
pub fn update(&mut self, time: DateTime<Local>) -> Vec<Item> {
|
||||
let mut b = Vec::with_capacity(self.index.len());
|
||||
self.index.retain(|i, &mut expires| {
|
||||
|
|
@ -45,9 +45,9 @@ impl Ban {
|
|||
b
|
||||
}
|
||||
|
||||
/// * returns expiration time
|
||||
/// * return expiration time
|
||||
pub fn add(&mut self, key: Id20) -> DateTime<Local> {
|
||||
let t = Local::now() + Duration::from_secs(self.index.len() as u64 * self.timeout);
|
||||
let t = self.index.values().max().map_or(Local::now(), |t| *t) + self.timeout;
|
||||
assert!(self.index.insert(key, t).is_none());
|
||||
t
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue