From 200225762d313411779e4e57b38ebadfa62c5b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Romero?= Date: Thu, 8 Oct 2026 14:03:19 +0000 Subject: [PATCH] perf: stream label rename preflight --- crates/flectar-mail-core/src/db/repo/labels.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/flectar-mail-core/src/db/repo/labels.rs b/crates/flectar-mail-core/src/db/repo/labels.rs index e18a0103..b307133b 100644 --- a/crates/flectar-mail-core/src/db/repo/labels.rs +++ b/crates/flectar-mail-core/src/db/repo/labels.rs @@ -194,20 +194,19 @@ pub fn save_with_descendants( let subtree_ids = std::iter::once(previous.id) .chain(descendants.iter().map(|label| label.id)) .collect::>(); - let target_names = std::iter::once(name.to_owned()) - .chain(descendants.iter().map(|label| { - format!( + let target_names = + std::iter::once(std::borrow::Cow::Borrowed(name)).chain(descendants.iter().map(|label| { + std::borrow::Cow::Owned(format!( "{replacement_prefix}{}", label.name.strip_prefix(&prefix).unwrap_or(&label.name) - ) - })) - .collect::>(); + )) + })); - for target in &target_names { + for target in target_names { if all_labels.iter().any(|label| { label.owner_account_id == previous.owner_account_id && !subtree_ids.contains(&label.id) - && label.name.eq_ignore_ascii_case(target) + && label.name.eq_ignore_ascii_case(&target) }) { return Err(CoreError::Other(format!( "a label named '{target}' already exists in this scope"