No longer packaging the vector of accounts in export.rs in Arc<Mutex<_>>
This commit is contained in:
parent
b65525cc6e
commit
7f949e3cdc
@ -19,32 +19,26 @@ async fn get_master_pass(
|
|||||||
dialogue: MainDialogue,
|
dialogue: MainDialogue,
|
||||||
master_pass: String,
|
master_pass: String,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let master_pass: Arc<str> = master_pass.into();
|
|
||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
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)
|
Account::get_all(user_id, &db)
|
||||||
.await?
|
.await?
|
||||||
.try_for_each_concurrent(None, |account| {
|
.try_for_each_concurrent(None, |account| {
|
||||||
let master_pass = Arc::clone(&master_pass);
|
let master_pass = Arc::clone(&master_pass);
|
||||||
let accounts = Arc::clone(&accounts);
|
|
||||||
async move {
|
async move {
|
||||||
let account =
|
let account = spawn_blocking(move || {
|
||||||
spawn_blocking(move || DecryptedAccount::from_account(account, &master_pass))
|
DecryptedAccount::from_account(account, &master_pass)
|
||||||
|
})
|
||||||
.await??;
|
.await??;
|
||||||
accounts.lock().await.push(account);
|
accounts.lock().await.push(account);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.await?;
|
.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));
|
accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name));
|
||||||
let json = to_vec_pretty(&User { accounts })?;
|
let json = to_vec_pretty(&User { accounts })?;
|
||||||
let file = InputFile::memory(json).file_name("accounts.json");
|
let file = InputFile::memory(json).file_name("accounts.json");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user