From 335750a29a83edba9bce2fb7e1452001e4962d1f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 5 Jan 2024 15:36:40 +0100 Subject: MOVE command is optimized --- src/mail/snapshot.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/mail/snapshot.rs (limited to 'src/mail/snapshot.rs') diff --git a/src/mail/snapshot.rs b/src/mail/snapshot.rs new file mode 100644 index 0000000..7256d50 --- /dev/null +++ b/src/mail/snapshot.rs @@ -0,0 +1,11 @@ +use std::sync::Arc; +use super::mailbox::Mailbox; +use super::uidindex::UidIndex; + +pub struct Snapshot { + pub mailbox: Arc, + pub snapshot: UidIndex, +} + +impl Snapshot { +} -- cgit v1.2.3 From adf4d33f226a745330a3bb802fe9b96f263a0895 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 5 Jan 2024 17:46:16 +0100 Subject: added some utility structures --- src/mail/snapshot.rs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/mail/snapshot.rs') diff --git a/src/mail/snapshot.rs b/src/mail/snapshot.rs index 7256d50..54bec64 100644 --- a/src/mail/snapshot.rs +++ b/src/mail/snapshot.rs @@ -1,11 +1,52 @@ use std::sync::Arc; + +use anyhow::Result; + use super::mailbox::Mailbox; use super::uidindex::UidIndex; -pub struct Snapshot { +/// A Frozen Mailbox has a snapshot of the current mailbox +/// state that is desynchronized with the real mailbox state. +/// It's up to the user to choose when their snapshot must be updated +/// to give useful information to their clients +/// +/// +pub struct FrozenMailbox { pub mailbox: Arc, pub snapshot: UidIndex, } -impl Snapshot { +impl FrozenMailbox { + /// Create a snapshot from a mailbox, the mailbox + the snapshot + /// becomes the "Frozen Mailbox". + pub async fn new(mailbox: Arc) -> Self { + let state = mailbox.current_uid_index().await; + + Self { + mailbox, + snapshot: state, + } + } + + /// Force the synchronization of the inner mailbox + /// but do not update the local snapshot + pub async fn sync(&self) -> Result<()> { + self.mailbox.opportunistic_sync().await + } + + /// Peek snapshot without updating the frozen mailbox + /// Can be useful if you want to plan some writes + /// while sending a diff to the client later + pub async fn peek(&self) -> UidIndex { + self.mailbox.current_uid_index().await + } + + /// Update the FrozenMailbox local snapshot. + /// Returns the old snapshot, so you can build a diff + pub async fn update(&mut self) -> UidIndex { + let old_snapshot = self.snapshot.clone(); + self.snapshot = self.mailbox.current_uid_index().await; + + old_snapshot + } } -- cgit v1.2.3 From 4806f7ff84c595ec6647744577388fe4fab33736 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 5 Jan 2024 18:59:19 +0100 Subject: WIP rewrite with a query manager --- src/mail/snapshot.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/mail/snapshot.rs') diff --git a/src/mail/snapshot.rs b/src/mail/snapshot.rs index 54bec64..c3145b4 100644 --- a/src/mail/snapshot.rs +++ b/src/mail/snapshot.rs @@ -4,6 +4,8 @@ use anyhow::Result; use super::mailbox::Mailbox; use super::uidindex::UidIndex; +use super::unique_ident::UniqueIdent; +use super::query::{Query, QueryScope}; /// A Frozen Mailbox has a snapshot of the current mailbox /// state that is desynchronized with the real mailbox state. @@ -49,4 +51,12 @@ impl FrozenMailbox { old_snapshot } + + pub fn query<'a, 'b>(&'a self, uuids: &'b [UniqueIdent], scope: QueryScope) -> Query<'a, 'b> { + Query { + frozen: self, + emails: uuids, + scope, + } + } } -- cgit v1.2.3 From 53dbf82cbce3cb17cbcffd09558677faf8702f54 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sat, 6 Jan 2024 11:33:56 +0100 Subject: Format code again --- src/mail/snapshot.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/mail/snapshot.rs') diff --git a/src/mail/snapshot.rs b/src/mail/snapshot.rs index c3145b4..0834f09 100644 --- a/src/mail/snapshot.rs +++ b/src/mail/snapshot.rs @@ -3,16 +3,16 @@ use std::sync::Arc; use anyhow::Result; use super::mailbox::Mailbox; +use super::query::{Query, QueryScope}; use super::uidindex::UidIndex; use super::unique_ident::UniqueIdent; -use super::query::{Query, QueryScope}; /// A Frozen Mailbox has a snapshot of the current mailbox /// state that is desynchronized with the real mailbox state. /// It's up to the user to choose when their snapshot must be updated /// to give useful information to their clients /// -/// +/// pub struct FrozenMailbox { pub mailbox: Arc, pub snapshot: UidIndex, @@ -46,17 +46,17 @@ impl FrozenMailbox { /// Update the FrozenMailbox local snapshot. /// Returns the old snapshot, so you can build a diff pub async fn update(&mut self) -> UidIndex { - let old_snapshot = self.snapshot.clone(); - self.snapshot = self.mailbox.current_uid_index().await; + let old_snapshot = self.snapshot.clone(); + self.snapshot = self.mailbox.current_uid_index().await; - old_snapshot + old_snapshot } pub fn query<'a, 'b>(&'a self, uuids: &'b [UniqueIdent], scope: QueryScope) -> Query<'a, 'b> { Query { - frozen: self, - emails: uuids, - scope, + frozen: self, + emails: uuids, + scope, } } } -- cgit v1.2.3