melib/LazyCountSet: set not_yet_seen to 0 when inserting existing

Not yet seen behavior is unreliable and leads to false unread counts.
Set it to 0 instead when inserting an existing count.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/443/head
Manos Pitsidianakis 3 months ago
parent a13bf13f24
commit 06437e607c
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -734,21 +734,13 @@ impl LazyCountSet {
} }
pub fn insert_existing(&mut self, new_val: EnvelopeHash) -> bool { pub fn insert_existing(&mut self, new_val: EnvelopeHash) -> bool {
if self.not_yet_seen == 0 { self.not_yet_seen = 0;
false self.set.insert(new_val)
} else {
if !self.set.contains(&new_val) {
self.not_yet_seen -= 1;
}
self.set.insert(new_val);
true
}
} }
pub fn insert_existing_set(&mut self, set: BTreeSet<EnvelopeHash>) { pub fn insert_existing_set(&mut self, set: BTreeSet<EnvelopeHash>) {
let old_len = self.set.len();
self.set.extend(set); self.set.extend(set);
self.not_yet_seen = self.not_yet_seen.saturating_sub(self.set.len() - old_len); self.not_yet_seen = 0;
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
@ -767,10 +759,12 @@ impl LazyCountSet {
} }
pub fn insert_new(&mut self, new_val: EnvelopeHash) { pub fn insert_new(&mut self, new_val: EnvelopeHash) {
self.not_yet_seen = 0;
self.set.insert(new_val); self.set.insert(new_val);
} }
pub fn insert_set(&mut self, set: BTreeSet<EnvelopeHash>) { pub fn insert_set(&mut self, set: BTreeSet<EnvelopeHash>) {
self.not_yet_seen = 0;
self.set.extend(set); self.set.extend(set);
} }

@ -32,6 +32,6 @@ fn test_lazy_count_set() {
assert!(new.insert_existing(EnvelopeHash(i))); assert!(new.insert_existing(EnvelopeHash(i)));
} }
assert_eq!(new.len(), 10); assert_eq!(new.len(), 10);
assert!(!new.insert_existing(EnvelopeHash(10))); assert!(new.insert_existing(EnvelopeHash(10)));
assert_eq!(new.len(), 10); assert_eq!(new.len(), 11);
} }

Loading…
Cancel
Save