perf: stop sending locations concurrently

This commit is contained in:
link2xt
2026-04-26 23:18:54 +02:00
parent 559953d8b5
commit 411158d045

View File

@@ -8,6 +8,7 @@ use std::sync::Arc;
use anyhow::{Context as _, Result, bail, ensure};
use async_channel::{self, Receiver, Sender};
use futures::FutureExt as _;
use futures::future;
use futures_lite::FutureExt as _;
use serde::{Deserialize, Serialize};
use tokio::fs;
@@ -553,9 +554,16 @@ impl Accounts {
/// Stops sending locations to all chats.
pub async fn stop_sending_locations(&self) -> Result<()> {
for account in self.accounts.values() {
location::stop_sending(account).await?;
}
future::try_join_all(
self.accounts
.iter()
.map(|(account_id, account)| async move {
location::stop_sending(account).await.with_context(|| {
format!("Failed to stop sending locations for account {account_id}")
})
}),
)
.await?;
Ok(())
}
}