From 38a20d0a78420857fabf360f1d93110582837445 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Thu, 25 Apr 2024 10:45:02 +1200 Subject: [PATCH] Bugfix in event orering (BTreeSet would only keep one event with the same created_at) --- chorus-lib/src/types/event/mod.rs | 4 +++- chorus-lib/src/types/id.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/chorus-lib/src/types/event/mod.rs b/chorus-lib/src/types/event/mod.rs index fe5f63d..1215282 100644 --- a/chorus-lib/src/types/event/mod.rs +++ b/chorus-lib/src/types/event/mod.rs @@ -205,7 +205,9 @@ impl PartialOrd for Event<'_> { impl Ord for Event<'_> { fn cmp(&self, other: &Self) -> Ordering { - self.created_at().cmp(&other.created_at()) + self.created_at() + .cmp(&other.created_at()) + .then(self.id().cmp(&other.id())) } } diff --git a/chorus-lib/src/types/id.rs b/chorus-lib/src/types/id.rs index 6027e11..a922eab 100644 --- a/chorus-lib/src/types/id.rs +++ b/chorus-lib/src/types/id.rs @@ -2,7 +2,7 @@ use crate::error::Error; use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Id(pub [u8; 32]); impl Id {