Skip to content

Conversation

@siddhijain
Copy link
Contributor

@siddhijain siddhijain commented Oct 9, 2025

FixesAB#3397557

This pull request refactors and optimizes account and credential filtering logic within the token cache implementation. The main focus is on improving performance and readability by streamlining filtering conditions and reducing unnecessary checks, especially in the methods that retrieve accounts and credentials. Additionally, some redundant imports are removed and logging is enhanced for better traceability.

Filtering Logic Improvements

  • Refactored the filtering process in AbstractAccountCredentialCache.java by immediately continuing to the next iteration when a match condition fails, rather than accumulating match state across conditions. This makes the code more efficient and easier to read.

Account Retrieval Logic

  • Rewrote the logic for retrieving accounts by local account ID and environment in MsalOAuth2TokenCache.java, now filtering accounts and credentials separately and checking for associated credentials before returning an account. This avoids unnecessary environment checks and improves clarity.

Codebase Maintenance

  • Removed unused imports and streamlined import statements in MsalOAuth2TokenCache.java for better maintainability.

These changes collectively improve the efficiency, readability, and maintainability of the account and credential filtering logic in the token cache.

@siddhijain siddhijain requested a review from a team as a code owner October 9, 2025 18:15
Copilot AI review requested due to automatic review settings October 9, 2025 18:15
@github-actions
Copy link

github-actions bot commented Oct 9, 2025

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors and optimizes the account and credential filtering logic in the token cache implementation to improve performance and readability. The changes focus on streamlining filtering conditions and reducing unnecessary checks when retrieving accounts and credentials.

  • Optimized filtering logic by using early returns instead of accumulating match state
  • Refactored account retrieval to filter accounts and credentials separately before checking associations
  • Added new imports and removed unused ones for better maintainability

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 18 comments.

File Description
MsalOAuth2TokenCache.java Refactored getAccountByLocalAccountId method to filter accounts and credentials separately, added new imports, and removed unused stream import
AbstractAccountCredentialCache.java Optimized filtering logic with early continue statements to improve performance and readability

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot changed the title Refactor get-account-by-local-account-id FixesAB#3397557 Refactor get-account-by-local-account-id FixesAB#3397557, Fixes AB#3397557 Oct 9, 2025
@github-actions
Copy link

github-actions bot commented Oct 9, 2025

✅ Work item link check complete. Description contains link AB#3397557 to an Azure Boards work item.

Copy link
Contributor

@melissaahn melissaahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@siddhijain siddhijain requested a review from a team as a code owner October 24, 2025 02:14
@siddhijain siddhijain added the Skip-Consumers-Check Only include this if making a breaking change purposefully, and there is an MSAL/ADAL/Broker PR label Oct 24, 2025
Copy link
Contributor

@mohitc1 mohitc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@siddhijain siddhijain merged commit adba95d into dev Oct 27, 2025
19 of 20 checks passed
@siddhijain siddhijain removed the Skip-Consumers-Check Only include this if making a breaking change purposefully, and there is an MSAL/ADAL/Broker PR label Oct 28, 2025
siddhijain added a commit that referenced this pull request Oct 28, 2025
…AB#3397557 (#2797)

Fixes[AB#3397557](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3397557)

Recently refactored getAccountByLocalAccountId method to first filter
both accounts and credentials on environment and then, check their
homeAccountId to match the accounts with credentials. However, that
refactoring does not work when environment passed is **null**. This
resulted in test failures in the broker repo.
#2781
 
This PR is to revert some of the changes made as part of that commit and
fix the failing tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants