From b90fd4287f08aff76c371aefe5ee82a5db2f9268 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 30 Jul 2025 23:37:02 -0400 Subject: [PATCH] client: Don't fetch the authenticated user once we have them (#35385) This PR makes it so we don't keep fetching the authenticated user once we have them. Release Notes: - N/A --- crates/client/src/cloud/user_store.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/client/src/cloud/user_store.rs b/crates/client/src/cloud/user_store.rs index da468ad618fc8f0000b603ec74207049930db402..ef4e92299a71bf0eec09e495efee40e8a90581c9 100644 --- a/crates/client/src/cloud/user_store.rs +++ b/crates/client/src/cloud/user_store.rs @@ -23,16 +23,23 @@ impl CloudUserStore { }; if cloud_client.has_credentials() { - if let Some(response) = cloud_client - .get_authenticated_user() - .await - .context("failed to fetch authenticated user") - .log_err() - { - this.update(cx, |this, _cx| { - this.authenticated_user = Some(Arc::new(response.user)); - }) - .ok(); + let already_fetched_authenticated_user = this + .read_with(cx, |this, _cx| this.authenticated_user().is_some()) + .unwrap_or(false); + + if already_fetched_authenticated_user { + // We already fetched the authenticated user; nothing to do. + } else { + let authenticated_user_result = cloud_client + .get_authenticated_user() + .await + .context("failed to fetch authenticated user"); + if let Some(response) = authenticated_user_result.log_err() { + this.update(cx, |this, _cx| { + this.authenticated_user = Some(Arc::new(response.user)); + }) + .ok(); + } } } else { this.update(cx, |this, _cx| {