From f843163c31b75839a2bf734fb8323cf79deb8ed2 Mon Sep 17 00:00:00 2001 From: Dillon Nys <24740863+dnys1@users.noreply.github.com> Date: Thu, 3 Aug 2023 09:52:16 -0700 Subject: [PATCH] perf(auth): Fetch auth session (#3510) fix(auth): Fetch auth session performance When a query is made to the credential store, we currently always hit the underlying store. However, due to the queuing nature of the store, if it's in a `success` state we can immediately return since we are guaranteed to have the latest data. --- .../state/machines/credential_store_state_machine.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/credential_store_state_machine.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/credential_store_state_machine.dart index 97384f583a..4ca8fd74f8 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/credential_store_state_machine.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/credential_store_state_machine.dart @@ -49,8 +49,12 @@ final class CredentialStoreStateMachine Future resolve(CredentialStoreEvent event) async { switch (event) { case CredentialStoreLoadCredentialStore _: - emit(const CredentialStoreState.loadingStoredCredentials()); - await onLoadCredentialStore(event); + if (currentState case final CredentialStoreSuccess success) { + emit(success); + } else { + emit(const CredentialStoreState.loadingStoredCredentials()); + await onLoadCredentialStore(event); + } case CredentialStoreStoreCredentials _: emit(const CredentialStoreState.storingCredentials()); await onStoreCredentials(event);