TCP connection creation overhead fixed by cloning once created TCP connection. Huge performance gain on login and register. Utilizing gRPC

This commit is contained in:
filipriec
2025-04-19 15:54:58 +02:00
parent 8b3aa5891e
commit 60ba17cfea
4 changed files with 21 additions and 29 deletions

View File

@@ -146,6 +146,7 @@ pub async fn back_to_main(
pub fn initiate_login(
login_state: &LoginState,
app_state: &mut AppState,
mut auth_client: AuthClient,
sender: mpsc::Sender<LoginResult>,
) -> String {
let username = login_state.username.clone();
@@ -166,17 +167,13 @@ pub fn initiate_login(
// 3. Spawn the login task
spawn(async move {
let login_outcome = match AuthClient::new().await {
Ok(mut auth_client) => {
match auth_client.login(username.clone(), password).await
.with_context(|| format!("Spawned login task failed for identifier: {}", username))
{
Ok(response) => LoginResult::Success(response),
Err(e) => LoginResult::Failure(format!("{}", e)),
}
}
Err(e) => LoginResult::ConnectionError(format!("Failed to create AuthClient: {}", e)),
};
// Use the passed-in (and moved) auth_client directly
let login_outcome = match auth_client.login(username.clone(), password).await
.with_context(|| format!("Spawned login task failed for identifier: {}", username))
{
Ok(response) => LoginResult::Success(response),
Err(e) => LoginResult::Failure(format!("{}", e)),
};
// Send result back to the main UI thread
if let Err(e) = sender.send(login_outcome).await {
error!("Failed to send login result: {}", e);