aboutsummaryrefslogtreecommitdiff
path: root/src/mail/mailbox.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-07-13 14:21:14 +0200
committerAlex Auvolat <alex@adnab.me>2022-07-13 14:21:14 +0200
commitcd59be3a007822637a8b48efe988fb052d58a756 (patch)
tree4f57f0720ed62e9c8704a6ca38a6a4c48b660f6d /src/mail/mailbox.rs
parent9fa2e958b3b37538b80b7f26107b7df2238f335b (diff)
downloadaerogramme-cd59be3a007822637a8b48efe988fb052d58a756.tar.gz
aerogramme-cd59be3a007822637a8b48efe988fb052d58a756.zip
Implement opportunistic sync based on watch value, and use it
Diffstat (limited to 'src/mail/mailbox.rs')
-rw-r--r--src/mail/mailbox.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs
index 4b84cf2..19a95e0 100644
--- a/src/mail/mailbox.rs
+++ b/src/mail/mailbox.rs
@@ -60,8 +60,14 @@ impl Mailbox {
}
/// Sync data with backing store
- pub async fn sync(&self) -> Result<()> {
- self.mbox.write().await.sync().await
+ pub async fn force_sync(&self) -> Result<()> {
+ self.mbox.write().await.force_sync().await
+ }
+
+ /// Sync data with backing store only if changes are detected
+ /// or last sync is too old
+ pub async fn opportunistic_sync(&self) -> Result<()> {
+ self.mbox.write().await.opportunistic_sync().await
}
// ---- Functions for reading the mailbox ----
@@ -184,11 +190,16 @@ struct MailboxInternal {
}
impl MailboxInternal {
- async fn sync(&mut self) -> Result<()> {
+ async fn force_sync(&mut self) -> Result<()> {
self.uid_index.sync().await?;
Ok(())
}
+ async fn opportunistic_sync(&mut self) -> Result<()> {
+ self.uid_index.opportunistic_sync().await?;
+ Ok(())
+ }
+
// ---- Functions for reading the mailbox ----
async fn fetch_meta(&self, ids: &[UniqueIdent]) -> Result<Vec<MailMeta>> {
@@ -308,7 +319,8 @@ impl MailboxInternal {
.insert_item(&self.mail_path, &ident.to_string(), meta_blob, None)
.await?;
Ok::<_, anyhow::Error>(())
- }
+ },
+ self.uid_index.opportunistic_sync()
)?;
// Add mail to Bayou mail index
@@ -357,7 +369,8 @@ impl MailboxInternal {
.insert_item(&self.mail_path, &ident.to_string(), meta_blob, None)
.await?;
Ok::<_, anyhow::Error>(())
- }
+ },
+ self.uid_index.opportunistic_sync()
)?;
// Add mail to Bayou mail index
@@ -449,6 +462,7 @@ impl MailboxInternal {
.await?;
Ok::<_, anyhow::Error>(())
},
+ self.uid_index.opportunistic_sync(),
)?;
// Add mail to Bayou mail index