From bce656c7876bd33dd8db45966823ff2c5ab60066 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 5 Feb 2019 11:52:11 +0000 Subject: [PATCH 1/5] Retry updating revision - fixes #383 --- src/db/models/user.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 127fa78a..390302a9 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -184,10 +184,12 @@ impl User { pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult { self.updated_at = Utc::now().naive_utc(); - diesel::update(users::table.filter(users::uuid.eq(&self.uuid))) - .set(users::updated_at.eq(&self.updated_at)) - .execute(&**conn) - .map_res("Error updating user revision") + crate::util::retry( || { + diesel::update(users::table.filter(users::uuid.eq(&self.uuid))) + .set(users::updated_at.eq(&self.updated_at)) + .execute(&**conn) + }, 10) + .map_res("Error updating user revision") } pub fn find_by_mail(mail: &str, conn: &DbConn) -> Option { From bd65c4e312219c3165b6aef92183bc84c082e9ef Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 5 Feb 2019 13:49:30 +0000 Subject: [PATCH 2/5] Remove superfluous cipher.save() call --- src/api/core/ciphers.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index bcf8c797..71cf7734 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -853,7 +853,6 @@ fn move_cipher_selected(data: JsonUpcase, headers: Headers, conn // Move cipher cipher.move_to_folder(data.FolderId.clone(), &user_uuid, &conn)?; - cipher.save(&conn)?; nt.send_cipher_update( UpdateType::CipherUpdate, From 1a5ecd4d4aaa3744b45d8e67c689335959f7cc1b Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 5 Feb 2019 13:52:30 +0000 Subject: [PATCH 3/5] cipher does not need to be mutable --- src/api/core/ciphers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 71cf7734..0db705e5 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -842,7 +842,7 @@ fn move_cipher_selected(data: JsonUpcase, headers: Headers, conn } for uuid in data.Ids { - let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) { + let cipher = match Cipher::find_by_uuid(&uuid, &conn) { Some(cipher) => cipher, None => err!("Cipher doesn't exist"), }; From b3f7394c06f78fd0019947d6d82f21fedd7a7db5 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 5 Feb 2019 14:09:59 +0000 Subject: [PATCH 4/5] Do not update revision at the end, as we already did that --- src/api/core/ciphers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 0db705e5..ab6a321d 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -857,7 +857,7 @@ fn move_cipher_selected(data: JsonUpcase, headers: Headers, conn nt.send_cipher_update( UpdateType::CipherUpdate, &cipher, - &User::update_uuid_revision(&user_uuid, &conn), + &vec![user_uuid.clone()] ); } From 637f655b6fe48fb8312b338d439a548911743057 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 5 Feb 2019 14:16:07 +0000 Subject: [PATCH 5/5] Do not allocate uneccessary Vec --- src/api/core/ciphers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index ab6a321d..2d03459f 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -857,7 +857,7 @@ fn move_cipher_selected(data: JsonUpcase, headers: Headers, conn nt.send_cipher_update( UpdateType::CipherUpdate, &cipher, - &vec![user_uuid.clone()] + &[user_uuid.clone()] ); }