Now using parking_lot's mutex in import and export
This commit is contained in:
parent
e1fb440991
commit
d3a55ea702
39
Cargo.lock
generated
39
Cargo.lock
generated
@ -711,7 +711,7 @@ checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1318,7 +1318,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"parking_lot_core",
|
"parking_lot_core 0.8.6",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core 0.9.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1330,11 +1340,24 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
"instant",
|
"instant",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall 0.2.16",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall 0.3.5",
|
||||||
|
"smallvec",
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pass_manager"
|
name = "pass_manager"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -1348,6 +1371,7 @@ dependencies = [
|
|||||||
"itertools 0.10.5",
|
"itertools 0.10.5",
|
||||||
"log",
|
"log",
|
||||||
"migration",
|
"migration",
|
||||||
|
"parking_lot 0.12.1",
|
||||||
"pretty_env_logger",
|
"pretty_env_logger",
|
||||||
"rayon",
|
"rayon",
|
||||||
"sea-orm",
|
"sea-orm",
|
||||||
@ -1628,6 +1652,15 @@ dependencies = [
|
|||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.8.4"
|
version = "1.8.4"
|
||||||
|
@ -21,6 +21,7 @@ futures = "0.3.28"
|
|||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
migration = { version = "0.2.0", path = "migration" }
|
migration = { version = "0.2.0", path = "migration" }
|
||||||
|
parking_lot = "0.12.1"
|
||||||
pretty_env_logger = "0.5.0"
|
pretty_env_logger = "0.5.0"
|
||||||
rayon = "1.7.0"
|
rayon = "1.7.0"
|
||||||
sea-orm = { version = "0.11.3", features = ["sqlx-mysql", "runtime-tokio-rustls"] }
|
sea-orm = { version = "0.11.3", features = ["sqlx-mysql", "runtime-tokio-rustls"] }
|
||||||
|
@ -6,11 +6,12 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use entity::prelude::*;
|
use entity::prelude::*;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
use parking_lot::Mutex;
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
use serde_json::to_vec_pretty;
|
use serde_json::to_vec_pretty;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use teloxide::{adaptors::Throttle, prelude::*, types::InputFile};
|
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
|
/// Decryptes the account on a worker thread and adds it to the accounts vector
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -21,7 +22,7 @@ async fn decrypt_account(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let account =
|
let account =
|
||||||
spawn_blocking(move || DecryptedAccount::from_account(account, &master_pass)).await??;
|
spawn_blocking(move || DecryptedAccount::from_account(account, &master_pass)).await??;
|
||||||
accounts.lock().await.push(account);
|
accounts.lock().push(account);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,11 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use futures::{stream, StreamExt};
|
use futures::{stream, StreamExt};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use parking_lot::Mutex;
|
||||||
use sea_orm::prelude::*;
|
use sea_orm::prelude::*;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use teloxide::{adaptors::Throttle, prelude::*};
|
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
|
/// 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
|
/// 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>>,
|
failed: &Mutex<&mut Vec<String>>,
|
||||||
) {
|
) {
|
||||||
if !account.validate() {
|
if !account.validate() {
|
||||||
failed.lock().await.push(account.name);
|
failed.lock().push(account.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let name = account.name.clone();
|
let name = account.name.clone();
|
||||||
match spawn_blocking(move || account.into_account(user_id, &master_pass)).await {
|
match spawn_blocking(move || account.into_account(user_id, &master_pass)).await {
|
||||||
Ok(Ok(account)) => match account.insert(db).await {
|
Ok(Ok(account)) => match account.insert(db).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => failed.lock().await.push(name),
|
Err(_) => failed.lock().push(name),
|
||||||
},
|
},
|
||||||
_ => failed.lock().await.push(name),
|
_ => failed.lock().push(name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user