Now using parking_lot's mutex in import and export
This commit is contained in:
@ -6,11 +6,12 @@ use crate::{
|
||||
};
|
||||
use entity::prelude::*;
|
||||
use futures::TryStreamExt;
|
||||
use parking_lot::Mutex;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use serde_json::to_vec_pretty;
|
||||
use std::sync::Arc;
|
||||
use teloxide::{adaptors::Throttle, prelude::*, types::InputFile};
|
||||
use tokio::{sync::Mutex, task::spawn_blocking};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
/// Decryptes the account on a worker thread and adds it to the accounts vector
|
||||
#[inline]
|
||||
@ -21,7 +22,7 @@ async fn decrypt_account(
|
||||
) -> crate::Result<()> {
|
||||
let account =
|
||||
spawn_blocking(move || DecryptedAccount::from_account(account, &master_pass)).await??;
|
||||
accounts.lock().await.push(account);
|
||||
accounts.lock().push(account);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,11 @@ use crate::{
|
||||
};
|
||||
use futures::{stream, StreamExt};
|
||||
use itertools::Itertools;
|
||||
use parking_lot::Mutex;
|
||||
use sea_orm::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use teloxide::{adaptors::Throttle, prelude::*};
|
||||
use tokio::{sync::Mutex, task::spawn_blocking};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
/// Ecryptes the account and adds it to the database
|
||||
/// If any of these steps fail, the account name will be added to the failed vector
|
||||
@ -22,16 +23,16 @@ async fn encrypt_account(
|
||||
failed: &Mutex<&mut Vec<String>>,
|
||||
) {
|
||||
if !account.validate() {
|
||||
failed.lock().await.push(account.name);
|
||||
failed.lock().push(account.name);
|
||||
return;
|
||||
}
|
||||
let name = account.name.clone();
|
||||
match spawn_blocking(move || account.into_account(user_id, &master_pass)).await {
|
||||
Ok(Ok(account)) => match account.insert(db).await {
|
||||
Ok(_) => (),
|
||||
Err(_) => failed.lock().await.push(name),
|
||||
Err(_) => failed.lock().push(name),
|
||||
},
|
||||
_ => failed.lock().await.push(name),
|
||||
_ => failed.lock().push(name),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user