summaryrefslogtreecommitdiffstats
path: root/melib
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-11-29 19:33:23 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-11-30 02:20:09 +0200
commit8e7583a32f7297fe2ea81c45fe319dd76e080b31 (patch)
treecda59413927aa71a81a548e8b16df3cd51b3b7a6 /melib
parent5f6b4745b8d266a8144202918c780f788a53816a (diff)
melib/imap: don't clear mailbox counts before fetching
Diffstat (limited to 'melib')
-rw-r--r--melib/src/backends.rs13
-rw-r--r--melib/src/backends/imap.rs27
2 files changed, 23 insertions, 17 deletions
diff --git a/melib/src/backends.rs b/melib/src/backends.rs
index 8e8e8f81..4b01d47a 100644
--- a/melib/src/backends.rs
+++ b/melib/src/backends.rs
@@ -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)]
diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs
index 135ab90f..cd4b809c 100644
--- a/melib/src/backends/imap.rs
+++ b/melib/src/backends/imap.rs
@@ -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);
}
}