diff options
Diffstat (limited to 'src/session.rs')
-rw-r--r-- | src/session.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/session.rs b/src/session.rs index aad299a..0118383 100644 --- a/src/session.rs +++ b/src/session.rs @@ -65,12 +65,12 @@ impl Sessions { let _guard = span.enter(); match self.inner.entry(item.name) { - Entry::Occupied(mut occupied) if &item.state > occupied.get() => { - tracing::trace!(?occupied, new_value=?item.state, "New entry is more recent, replacing"); - occupied.insert(item.state); + Entry::Occupied(mut o) if item.state.is_better_than(o.get()) => { + tracing::trace!(prev=?o, ?item.state, "New entry is more recent or accurate, replacing"); + o.insert(item.state); } - Entry::Occupied(occupied) => { - tracing::trace!(?occupied, new_value=?item.state, "Previous entry is more recent, skipping"); + Entry::Occupied(o) => { + tracing::trace!(existing=?o, ?item.state, "Existing entry is more recent or accurate, skipping"); } Entry::Vacant(v) => { tracing::trace!(?item.state, "No previous entry exists, inserting"); @@ -98,6 +98,16 @@ pub enum State { LocalHost, } +impl State { + pub fn is_better_than(&self, state: &State) -> bool { + match (self, state) { + (&State::LocalHost, _) => false, + (_, &State::LocalHost) => true, + _ => self > state, + } + } +} + mod epoch_timestamp { use std::time::Duration; |