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,
 | 
					    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();
 | 
				
			||||||
    Account::get_all(user_id, &db)
 | 
					    {
 | 
				
			||||||
        .await?
 | 
					        let accounts = &Mutex::new(&mut accounts);
 | 
				
			||||||
        .try_for_each_concurrent(None, |account| {
 | 
					        let master_pass: Arc<str> = master_pass.into();
 | 
				
			||||||
            let master_pass = Arc::clone(&master_pass);
 | 
					        Account::get_all(user_id, &db)
 | 
				
			||||||
            let accounts = Arc::clone(&accounts);
 | 
					            .await?
 | 
				
			||||||
            async move {
 | 
					            .try_for_each_concurrent(None, |account| {
 | 
				
			||||||
                let account =
 | 
					                let master_pass = Arc::clone(&master_pass);
 | 
				
			||||||
                    spawn_blocking(move || DecryptedAccount::from_account(account, &master_pass))
 | 
					                async move {
 | 
				
			||||||
                        .await??;
 | 
					                    let account = spawn_blocking(move || {
 | 
				
			||||||
                accounts.lock().await.push(account);
 | 
					                        DecryptedAccount::from_account(account, &master_pass)
 | 
				
			||||||
                Ok(())
 | 
					                    })
 | 
				
			||||||
            }
 | 
					                    .await??;
 | 
				
			||||||
        })
 | 
					                    accounts.lock().await.push(account);
 | 
				
			||||||
        .await?;
 | 
					                    Ok(())
 | 
				
			||||||
    drop(master_pass);
 | 
					                }
 | 
				
			||||||
    let mut accounts = match Arc::try_unwrap(accounts) {
 | 
					            })
 | 
				
			||||||
        Ok(account) => account.into_inner(),
 | 
					            .await?;
 | 
				
			||||||
        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");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user