melib/imap: don't clear mailbox counts before fetching

jmap-eventsource
Manos Pitsidianakis 2020-11-29 19:33:23 +02:00
parent 5f6b4745b8
commit 8e7583a32f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 23 additions and 17 deletions

View File

@ -647,15 +647,10 @@ impl LazyCountSet {
}
}
pub fn insert_existing_set(&mut self, set: BTreeSet<EnvelopeHash>) -> bool {
if self.not_yet_seen < set.len() {
false
} else {
let old_len = self.set.len();
self.set.extend(set.into_iter());
self.not_yet_seen -= self.set.len() - old_len;
true
}
pub fn insert_existing_set(&mut self, set: BTreeSet<EnvelopeHash>) {
let old_len = self.set.len();
self.set.extend(set.into_iter());
self.not_yet_seen = self.not_yet_seen.saturating_sub(self.set.len() - old_len);
}
#[inline(always)]

View File

@ -343,12 +343,24 @@ impl MailBackend for ImapType {
cache_handle,
};
/* do this in a closure to prevent recursion limit error in async_stream macro */
let prepare_cl = |f: &ImapMailbox| {
f.set_warm(true);
if let Ok(mut exists) = f.exists.lock() {
let total = exists.len();
exists.clear();
exists.set_not_yet_seen(total);
}
if let Ok(mut unseen) = f.unseen.lock() {
let total = unseen.len();
unseen.clear();
unseen.set_not_yet_seen(total);
}
};
Ok(Box::pin(async_stream::try_stream! {
{
let f = &state.uid_store.mailboxes.lock().await[&mailbox_hash];
f.exists.lock().unwrap().clear();
f.unseen.lock().unwrap().clear();
f.set_warm(true);
prepare_cl(f);
if f.no_select {
yield vec![];
return;
@ -1629,7 +1641,7 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result<Vec<Envelope>> {
let f = &state.uid_store.mailboxes.lock().await[&state.mailbox_hash];
(f.exists.clone(), f.unseen.clone())
};
unseen.lock().unwrap().insert_set(
unseen.lock().unwrap().insert_existing_set(
cached_payload
.iter()
.filter_map(|env| {
@ -1641,10 +1653,9 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result<Vec<Envelope>> {
})
.collect(),
);
mailbox_exists
.lock()
.unwrap()
.insert_set(cached_payload.iter().map(|env| env.hash()).collect::<_>());
mailbox_exists.lock().unwrap().insert_existing_set(
cached_payload.iter().map(|env| env.hash()).collect::<_>(),
);
return Ok(cached_payload);
}
}