From 9e984151ef29852ef7af226705d62160ac5b68e6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2026 09:31:13 +0800 Subject: [PATCH] Bump user revision once for bulk cipher move move_cipher_selected called Cipher::move_to_folder in a loop, and every call bumped the same user's revision, so moving N ciphers did N identical revision updates. Add a variant that leaves the bump to the caller and use it for the bulk move, bumping once afterwards (also when a move fails halfway, as earlier ciphers are already moved). Cipher::move_to_folder itself is unchanged, so the single-cipher paths behave exactly as before. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01RJZPtN8D6FXs3E2x85EodL --- src/api/core/ciphers.rs | 14 ++++++++++++-- src/db/models/cipher.rs | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 46766896..bf284dde 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -23,7 +23,7 @@ use crate::{ models::{ Archive, Attachment, AttachmentId, Cipher, CipherId, Collection, CollectionCipher, CollectionGroup, CollectionId, CollectionUser, EventType, Favorite, Folder, FolderCipher, FolderId, Group, KeyId, - Membership, MembershipType, OrgPolicy, OrgPolicyType, OrganizationId, RepromptType, Send, UserId, + Membership, MembershipType, OrgPolicy, OrgPolicyType, OrganizationId, RepromptType, Send, User, UserId, }, }, util::{NumberOrString, deser_opt_nonempty_str, save_temp_file}, @@ -1659,12 +1659,22 @@ async fn move_cipher_selected( // Find all ciphers a user has access to, all others will be ignored let accessible_ciphers = Cipher::find_by_user_and_ciphers(user_id, &data.ids, &conn).await; let accessible_ciphers_count = accessible_ciphers.len(); + let mut move_result = Ok(()); for cipher in accessible_ciphers { - cipher.move_to_folder(data.folder_id.clone(), user_id, &conn).await?; + move_result = cipher.move_to_folder_without_revision_update(data.folder_id.clone(), user_id, &conn).await; + if move_result.is_err() { + break; + } if cipher_count == 1 { single_cipher = Some(cipher); } } + // Update the revision once for the whole batch. Also when a move failed halfway, + // since the ciphers moved before it are already changed. + if accessible_ciphers_count > 0 { + User::update_uuid_revision(user_id, &conn).await; + } + move_result?; if let Some(cipher) = single_cipher { nt.send_cipher_update( diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index f39b0bfc..3ceda88d 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -510,7 +510,16 @@ impl Cipher { conn: &DbConn, ) -> EmptyResult { User::update_uuid_revision(user_uuid, conn).await; + self.move_to_folder_without_revision_update(folder_uuid, user_uuid, conn).await + } + /// Same as `move_to_folder`, but the caller is responsible for updating the user's revision. + pub async fn move_to_folder_without_revision_update( + &self, + folder_uuid: Option, + user_uuid: &UserId, + conn: &DbConn, + ) -> EmptyResult { match (self.get_folder_uuid(user_uuid, conn).await, folder_uuid) { // No changes (None, None) => Ok(()),