diff --git a/rust/src/concepts/filter.rs b/rust/src/concepts/filter.rs index 50a1153..f68097e 100644 --- a/rust/src/concepts/filter.rs +++ b/rust/src/concepts/filter.rs @@ -12,7 +12,7 @@ use serde::Deserialize; use super::{ messages::{Match, Time, MAT}, - Action, ActionFilter, Pattern, Patterns, + Action, ActionFilter, LogEntry, Pattern, Patterns, }; use crate::{daemon::ExecsManagerInput, utils::parse_duration}; @@ -73,10 +73,6 @@ impl Filter { self.retry_duration } - pub fn longuest_action_duration(&self) -> TimeDelta { - self.longuest_action_duration - } - pub fn setup( &mut self, stream_name: &str, @@ -215,6 +211,14 @@ impl Filter { tx.send(ExecsManagerInput::Exec(mat)).unwrap(); } } + + pub fn is_outdated(entry: &LogEntry, now: &Time) -> bool { + if entry.exec { + entry.t + entry.f.longuest_action_duration < *now + } else { + entry.t + entry.f.retry_duration.unwrap_or_default() < *now + } + } } impl Display for Filter { diff --git a/rust/src/daemon/database/mod.rs b/rust/src/daemon/database/mod.rs index 2d98781..270d77e 100644 --- a/rust/src/daemon/database/mod.rs +++ b/rust/src/daemon/database/mod.rs @@ -235,15 +235,14 @@ fn __rotate_db( } // Store match & store in db - #[allow(clippy::unwrap_used)] // 0 second is obviously less seconds than i64::MAX - if (!entry.exec && entry.t + entry.f.retry_duration().unwrap_or_default() > now) - || (entry.exec && entry.t + entry.f.longuest_action_duration() > now) - { - // We loose subsecond precision when storing times, so we add those fake - // milliseconds to make sure each time is unique - - entry.t += TimeDelta::new(0, millisecond_disambiguation_counter).unwrap(); - millisecond_disambiguation_counter += 1; + if !Filter::is_outdated(&entry, &now) { + #[allow(clippy::unwrap_used)] // 0 second is obviously less than i64::MAX + { + // We loose subsecond precision when storing times, so we add those fake + // milliseconds to make sure each time is unique + entry.t += TimeDelta::new(0, millisecond_disambiguation_counter).unwrap(); + millisecond_disambiguation_counter += 1; + } if let Some(tx) = matches_tx { debug!("DB sending match from DB: {:?}", entry.m);