mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-06-09 12:33:53 +00:00
Fixed some clippy lints and changed update_uuid_revision to only use one db query
This commit is contained in:
parent
ef63342e20
commit
8b4a6f2a64
8 changed files with 32 additions and 27 deletions
|
@ -15,7 +15,7 @@ pub struct TwoFactor {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(FromPrimitive, ToPrimitive)]
|
||||
#[derive(FromPrimitive)]
|
||||
pub enum TwoFactorType {
|
||||
Authenticator = 0,
|
||||
Email = 1,
|
||||
|
|
|
@ -172,23 +172,27 @@ impl User {
|
|||
.map_res("Error deleting user")
|
||||
}
|
||||
|
||||
pub fn update_uuid_revision(uuid: &str, conn: &DbConn) -> Vec<String> {
|
||||
if let Some(mut user) = User::find_by_uuid(&uuid, conn) {
|
||||
if user.update_revision(conn).is_err() {
|
||||
warn!("Failed to update revision for {}", user.email);
|
||||
};
|
||||
};
|
||||
|
||||
vec![uuid.to_string()]
|
||||
pub fn update_uuid_revision(uuid: &str, conn: &DbConn) {
|
||||
if let Err(e) = Self::_update_revision(uuid, &Utc::now().naive_utc(), conn) {
|
||||
warn!("Failed to update revision for {}: {:#?}", uuid, e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult {
|
||||
self.updated_at = Utc::now().naive_utc();
|
||||
crate::util::retry( || {
|
||||
diesel::update(users::table.filter(users::uuid.eq(&self.uuid)))
|
||||
.set(users::updated_at.eq(&self.updated_at))
|
||||
.execute(&**conn)
|
||||
}, 10)
|
||||
|
||||
Self::_update_revision(&self.uuid, &self.updated_at, conn)
|
||||
}
|
||||
|
||||
fn _update_revision(uuid: &str, date: &NaiveDateTime, conn: &DbConn) -> EmptyResult {
|
||||
crate::util::retry(
|
||||
|| {
|
||||
diesel::update(users::table.filter(users::uuid.eq(uuid)))
|
||||
.set(users::updated_at.eq(date))
|
||||
.execute(&**conn)
|
||||
},
|
||||
10,
|
||||
)
|
||||
.map_res("Error updating user revision")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue