From b5b57b7ac9e2f428c6cd908bd6c55d7aa24776b9 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 6 Aug 2024 17:57:01 +0300 Subject: [PATCH] fix: flush after backtrack --- src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8a89003..736d95c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,15 +35,13 @@ struct EventSender { impl EventSender { fn submit(&self, event_builder: EventBuilder) -> Result { { - // Flush if oldest event older than a minute + // Always flush if oldest event older than a minute or newer than now let borrow = self.queue.borrow(); - if let Some(event) = borrow.first() { - let old = event.created_at < Timestamp::now().sub(60u64); + let min = Timestamp::now().sub(60u64); + if borrow.iter().any(|e| e.created_at < min || e.created_at > Timestamp::now()) { drop(borrow); - if old { - debug!("Flushing event queue because it is older than a minute"); - self.force_flush(); - } + debug!("Flushing event queue because it is older than a minute"); + self.force_flush(); } } let mut queue = self.queue.borrow_mut();