~soywod/pimalaya

email-lib: box the envelope inside EmailSyncCacheHunk::insert v1 REJECTED

Perma Alesheikh: 1
 box the envelope inside EmailSyncCacheHunk::insert

 4 files changed, 14 insertions(+), 24 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~soywod/pimalaya/patches/49347/mbox | git am -3
Learn more about email & git

[PATCH email-lib] box the envelope inside EmailSyncCacheHunk::insert Export this patch

Since the envelopes are comparitivally massive (~250) the owned copy
inside the enum causes the enum size to increase from ~64 to ~300.
By boxing them, we can reduce the size of EmailSyncCacheHunk and
pass around the heap allocated pointer, instead of cloning the value.
Signed-off-by: Perma Alesheikh <me@prma.dev>
---
 email/src/email/sync/cache.rs  |  6 +++---
 email/src/email/sync/hunk.rs   |  2 +-
 email/src/email/sync/patch.rs  | 14 ++------------
 email/src/email/sync/runner.rs | 16 ++++++++--------
 4 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/email/src/email/sync/cache.rs b/email/src/email/sync/cache.rs
index 2e807b4..ea05de6 100644
--- a/email/src/email/sync/cache.rs
+++ b/email/src/email/sync/cache.rs
@@ -120,7 +120,7 @@ fn insert_envelope(
        transaction: &Transaction,
        account: impl AsRef<str>,
        folder: impl AsRef<str>,
        envelope: Envelope,
        envelope: &Envelope,
    ) -> Result<()> {
        if envelope.flags.is_empty() {
            transaction.execute(
@@ -163,7 +163,7 @@ pub fn insert_local_envelope(
        tx: &Transaction,
        name: impl ToString,
        folder: impl AsRef<str>,
        envelope: Envelope,
        envelope: &Envelope,
    ) -> Result<()> {
        Self::insert_envelope(tx, name.to_string() + Self::LOCAL_SUFFIX, folder, envelope)
    }
@@ -172,7 +172,7 @@ pub fn insert_remote_envelope(
        tx: &Transaction,
        name: impl AsRef<str>,
        folder: impl AsRef<str>,
        envelope: Envelope,
        envelope: &Envelope,
    ) -> Result<()> {
        Self::insert_envelope(tx, name, folder, envelope)
    }
diff --git a/email/src/email/sync/hunk.rs b/email/src/email/sync/hunk.rs
index 55c1dcc..83c2d34 100644
--- a/email/src/email/sync/hunk.rs
+++ b/email/src/email/sync/hunk.rs
@@ -108,7 +108,7 @@ pub fn folder(&self) -> &str {
pub enum EmailSyncCacheHunk {
    /// The email matching the given envelope identifier needs to be
    /// added to the cache for the given destination.
    Insert(FolderName, Envelope, Target),
    Insert(FolderName, Box<Envelope>, Target),

    /// The email matching the given identifier needs to be removed
    /// from the cache for the given destination.
diff --git a/email/src/email/sync/patch.rs b/email/src/email/sync/patch.rs
index da6d1fd..713ee41 100644
--- a/email/src/email/sync/patch.rs
+++ b/email/src/email/sync/patch.rs
@@ -226,20 +226,10 @@ pub async fn apply_patch(
                for hunk in &report.cache_patch.0 {
                    match hunk {
                        EmailSyncCacheHunk::Insert(folder, envelope, Target::Local) => {
                            EmailSyncCache::insert_local_envelope(
                                &tx,
                                account,
                                folder,
                                envelope.clone(),
                            )?
                            EmailSyncCache::insert_local_envelope(&tx, account, folder, envelope)?
                        }
                        EmailSyncCacheHunk::Insert(folder, envelope, Target::Remote) => {
                            EmailSyncCache::insert_remote_envelope(
                                &tx,
                                account,
                                folder,
                                envelope.clone(),
                            )?
                            EmailSyncCache::insert_remote_envelope(&tx, account, folder, envelope)?
                        }
                        EmailSyncCacheHunk::Delete(folder, internal_id, Target::Local) => {
                            EmailSyncCache::delete_local_envelope(
diff --git a/email/src/email/sync/runner.rs b/email/src/email/sync/runner.rs
index 129660e..1a1b6d5 100644
--- a/email/src/email/sync/runner.rs
+++ b/email/src/email/sync/runner.rs
@@ -56,7 +56,7 @@ async fn process_hunk(
                let envelope = local.get_envelope(folder, &Id::single(id)).await?;
                vec![EmailSyncCacheHunk::Insert(
                    folder.clone(),
                    envelope.clone(),
                    Box::new(envelope),
                    Destination::Local,
                )]
            }
@@ -64,7 +64,7 @@ async fn process_hunk(
                let envelope = remote.get_envelope(folder, &Id::single(id)).await?;
                vec![EmailSyncCacheHunk::Insert(
                    folder.clone(),
                    envelope.clone(),
                    Box::new(envelope),
                    Destination::Remote,
                )]
            }
@@ -82,7 +82,7 @@ async fn process_hunk(
                        if *refresh_source_cache {
                            cache_hunks.push(EmailSyncCacheHunk::Insert(
                                folder.clone(),
                                envelope.clone(),
                                Box::new(envelope.to_owned()),
                                Destination::Local,
                            ))
                        };
@@ -92,7 +92,7 @@ async fn process_hunk(
                        if *refresh_source_cache {
                            cache_hunks.push(EmailSyncCacheHunk::Insert(
                                folder.clone(),
                                envelope.clone(),
                                Box::new(envelope.to_owned()),
                                Destination::Remote,
                            ))
                        };
@@ -113,7 +113,7 @@ async fn process_hunk(
                        let envelope = local.get_envelope(folder, &Id::single(id)).await?;
                        cache_hunks.push(EmailSyncCacheHunk::Insert(
                            folder.clone(),
                            envelope.clone(),
                            Box::new(envelope),
                            Destination::Local,
                        ));
                    }
@@ -124,7 +124,7 @@ async fn process_hunk(
                        let envelope = remote.get_envelope(folder, &Id::single(id)).await?;
                        cache_hunks.push(EmailSyncCacheHunk::Insert(
                            folder.clone(),
                            envelope.clone(),
                            Box::new(envelope),
                            Destination::Remote,
                        ));
                    }
@@ -166,7 +166,7 @@ async fn process_hunk(
                    ),
                    EmailSyncCacheHunk::Insert(
                        folder.clone(),
                        envelope.clone(),
                        Box::new(envelope.to_owned()),
                        Destination::Local,
                    ),
                ]
@@ -186,7 +186,7 @@ async fn process_hunk(
                    ),
                    EmailSyncCacheHunk::Insert(
                        folder.clone(),
                        envelope.clone(),
                        Box::new(envelope.to_owned()),
                        Destination::Remote,
                    ),
                ]
-- 
2.43.0