diff options
author | BlackDex <[email protected]> | 2021-11-16 17:07:55 +0100 |
---|---|---|
committer | Daniel GarcĂa <[email protected]> | 2022-02-27 21:37:23 +0100 |
commit | 87e08b9e50083d5b4aa3219ae5dcb67213427486 (patch) | |
tree | c3d8e80293927817cf4317d034bfdcd4d512be35 /src/db/models/favorite.rs | |
parent | 0b7d6bf6df5a83dcc95d063baa04d8818eb9d7db (diff) | |
download | vaultwarden-87e08b9e50083d5b4aa3219ae5dcb67213427486.tar.gz vaultwarden-87e08b9e50083d5b4aa3219ae5dcb67213427486.zip |
Async/Awaited all db methods
This is a rather large PR which updates the async branch to have all the
database methods as an async fn.
Some iter/map logic needed to be changed to a stream::iter().then(), but
besides that most changes were just adding async/await where needed.
Diffstat (limited to 'src/db/models/favorite.rs')
-rw-r--r-- | src/db/models/favorite.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/db/models/favorite.rs b/src/db/models/favorite.rs index cb3e3420..4ff31939 100644 --- a/src/db/models/favorite.rs +++ b/src/db/models/favorite.rs @@ -19,7 +19,7 @@ use crate::error::MapResult; impl Favorite { // Returns whether the specified cipher is a favorite of the specified user. - pub fn is_favorite(cipher_uuid: &str, user_uuid: &str, conn: &DbConn) -> bool { + pub async fn is_favorite(cipher_uuid: &str, user_uuid: &str, conn: &DbConn) -> bool { db_run! { conn: { let query = favorites::table .filter(favorites::cipher_uuid.eq(cipher_uuid)) @@ -31,11 +31,11 @@ impl Favorite { } // Sets whether the specified cipher is a favorite of the specified user. - pub fn set_favorite(favorite: bool, cipher_uuid: &str, user_uuid: &str, conn: &DbConn) -> EmptyResult { - let (old, new) = (Self::is_favorite(cipher_uuid, user_uuid, conn), favorite); + pub async fn set_favorite(favorite: bool, cipher_uuid: &str, user_uuid: &str, conn: &DbConn) -> EmptyResult { + let (old, new) = (Self::is_favorite(cipher_uuid, user_uuid, conn).await, favorite); match (old, new) { (false, true) => { - User::update_uuid_revision(user_uuid, conn); + User::update_uuid_revision(user_uuid, conn).await; db_run! { conn: { diesel::insert_into(favorites::table) .values(( @@ -47,7 +47,7 @@ impl Favorite { }} } (true, false) => { - User::update_uuid_revision(user_uuid, conn); + User::update_uuid_revision(user_uuid, conn).await; db_run! { conn: { diesel::delete( favorites::table @@ -64,7 +64,7 @@ impl Favorite { } // Delete all favorite entries associated with the specified cipher. - pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> EmptyResult { + pub async fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> EmptyResult { db_run! { conn: { diesel::delete(favorites::table.filter(favorites::cipher_uuid.eq(cipher_uuid))) .execute(conn) @@ -73,7 +73,7 @@ impl Favorite { } // Delete all favorite entries associated with the specified user. - pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { + pub async fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { db_run! { conn: { diesel::delete(favorites::table.filter(favorites::user_uuid.eq(user_uuid))) .execute(conn) |