Browse Source

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RJZPtN8D6FXs3E2x85EodL
pull/7840/head
Michael 1 month ago
parent
commit
9e984151ef
  1. 14
      src/api/core/ciphers.rs
  2. 9
      src/db/models/cipher.rs

14
src/api/core/ciphers.rs

@ -23,7 +23,7 @@ use crate::{
models::{ models::{
Archive, Attachment, AttachmentId, Cipher, CipherId, Collection, CollectionCipher, CollectionGroup, Archive, Attachment, AttachmentId, Cipher, CipherId, Collection, CollectionCipher, CollectionGroup,
CollectionId, CollectionUser, EventType, Favorite, Folder, FolderCipher, FolderId, Group, KeyId, 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}, 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 // 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 = Cipher::find_by_user_and_ciphers(user_id, &data.ids, &conn).await;
let accessible_ciphers_count = accessible_ciphers.len(); let accessible_ciphers_count = accessible_ciphers.len();
let mut move_result = Ok(());
for cipher in accessible_ciphers { 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 { if cipher_count == 1 {
single_cipher = Some(cipher); 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 { if let Some(cipher) = single_cipher {
nt.send_cipher_update( nt.send_cipher_update(

9
src/db/models/cipher.rs

@ -510,7 +510,16 @@ impl Cipher {
conn: &DbConn, conn: &DbConn,
) -> EmptyResult { ) -> EmptyResult {
User::update_uuid_revision(user_uuid, conn).await; 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<FolderId>,
user_uuid: &UserId,
conn: &DbConn,
) -> EmptyResult {
match (self.get_folder_uuid(user_uuid, conn).await, folder_uuid) { match (self.get_folder_uuid(user_uuid, conn).await, folder_uuid) {
// No changes // No changes
(None, None) => Ok(()), (None, None) => Ok(()),

Loading…
Cancel
Save