No longer packaging the vector of accounts in export.rs in Arc<Mutex<_>>
This commit is contained in:
		@@ -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()));
 | 
			
		||||
    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))
 | 
			
		||||
                        .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",
 | 
			
		||||
            ))
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    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);
 | 
			
		||||
                async move {
 | 
			
		||||
                    let account = spawn_blocking(move || {
 | 
			
		||||
                        DecryptedAccount::from_account(account, &master_pass)
 | 
			
		||||
                    })
 | 
			
		||||
                    .await??;
 | 
			
		||||
                    accounts.lock().await.push(account);
 | 
			
		||||
                    Ok(())
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .await?;
 | 
			
		||||
    }
 | 
			
		||||
    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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user