No longer packaging the vector of accounts in export.rs in Arc<Mutex<_>>

This commit is contained in:
StNicolay 2023-05-14 13:06:48 +03:00
parent b65525cc6e
commit 7f949e3cdc
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D

View File

@ -19,32 +19,26 @@ async fn get_master_pass(
dialogue: MainDialogue,
master_pass: String,
) -> crate::Result<()> {
let master_pass: Arc<str> = master_pass.into();
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let accounts = Arc::new(Mutex::new(Vec::new()));
let mut accounts = Vec::new();
{
let accounts = &Mutex::new(&mut accounts);
let master_pass: Arc<str> = master_pass.into();
Account::get_all(user_id, &db)
.await?
.try_for_each_concurrent(None, |account| {
let master_pass = Arc::clone(&master_pass);
let accounts = Arc::clone(&accounts);
async move {
let account =
spawn_blocking(move || DecryptedAccount::from_account(account, &master_pass))
let account = spawn_blocking(move || {
DecryptedAccount::from_account(account, &master_pass)
})
.await??;
accounts.lock().await.push(account);
Ok(())
}
})
.await?;
drop(master_pass);
let mut accounts = match Arc::try_unwrap(accounts) {
Ok(account) => account.into_inner(),
Err(_) => {
return Err(crate::Error::msg(
"Couldn't get accounts from Arc in export.rs",
))
}
};
accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name));
let json = to_vec_pretty(&User { accounts })?;
let file = InputFile::memory(json).file_name("accounts.json");