Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALS-6235] Investigate: BDC Auth login issue: Explore delays creating the user roles #173

Merged
merged 24 commits into from
May 28, 2024

Conversation

Gcolon021
Copy link
Contributor

@Gcolon021 Gcolon021 commented May 28, 2024

[ALS-6235] Investigate: BDC Auth login issue: Explore delays creating the user roles

  • FenceAuthorization service has been refactored to improve readability and modularity.
  • Fence mapping utility now loads the fence mapping json data on application startup and initializes two maps used by the application. This reduced execution time from ~13.25 minutes to ~9 minutes.
  • AccessRules now uses a cache when creating new AccessRules. This reduces the time spent querying the database as many access rules are reused by privileges. This change reduced execution time from ~9 minutes down to 2.25 - 2.5 minutes.
  • Refactor Role creation to allow for parallelization. This reduced execution time from 2.25 - 2.5 minutes down to ~30seconds.
  • Roles are no longer removed from the user on login. We now update the user roles in place.

Move AccessRule creation out to a separate method. Centralizing this will make it is to optimize more in the near future.
The code changes refactor the FENCEAuthenticationService class to enhance code readability and performance. This includes introducing a new `_authZMap` for faster lookups and reorganizing methods for better code reusability.
We need to call this at least once in order to load the maps.
A new utility class (FenceMappingUtility) has been introduced to handle FENCE mapping operations. The FenceMappingUtility is now used for FENCE mapping in FENCEAuthenticationService and StudyAccessService instead of these classes handling it directly. This change makes the applications more modular, distributes responsibilities better among classes, and improves code readability.
In the FenceMappingUtility class, the data structures have been updated to improve the thread safety of the application. The non-thread-safe HashMap was replaced with ConcurrentHashMap to handle potential concurrency issues. To further strengthen thread safety, the 'volatile' keyword was added to provide the most recent value whenever a variable is called, directly addressing potential issues with thread caching. The method 'initializeFENCEMappings' was also modified to use a parallel stream for efficient data processing.
Refactor upsertTopmedPrivilege to improve readability and make future improvements easier. Refactor getAllowedQueryTypeRules to cache fence_allowed_query_types.
A null-check has been added before using the standardAccessRules variable to safeguard against potential NullPointerException. The logic has also been reconsidered, and now it only attempts to populate the standardAccessRules set from the database if it is found to be empty or null. This should enhance efficiency by avoiding unnecessary database calls.
The role creation and assignment process has been optimized in the FENCEAuthenticationService. Rather than processing roles one-by-one, the revised code collects all the role names, prepares a list of roles, and commits them all at once to the repository. This is achieved by leveraging Java's parallel streams and the 'persistAll' method added to RoleRepository.
A check has been added in the createRole method to handle the situation when the role name is empty. It prevents the creation of roles with empty names, logging an error message
The persistAll method in the RoleRepository has been updated. This change ensures that if a role already has a UUID, it is merged instead of persisted, preventing any duplicate entries. New roles, which do not yet have a UUID, are persisted as before.
FENCEAuthenticationService.java has been refactored to improve role handling. The logic is now more precise and efficient in checking the existence of roles, adding new ones, and removing obsolete ones. It ensures correct persistence of roles while providing better error handling and logging.
The previous code used to find roles that aren't present in a user's existing roles, but the following logic left it unused. Thus, this redundancy has been removed, streamlining the process of handling roles in the FENCEAuthenticationService class.
}
}

private synchronized void initializeFENCEMappings() {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, remove synchronized here

Performance timing for user login within the FENCEAuthenticationService was removed to clean up the code. This logging was unnecessary and did not contribute in any significant manner to the overall functionality.
@Gcolon021 Gcolon021 merged commit ce9c376 into fence-integration-release/0005 May 28, 2024
2 checks passed
@Gcolon021 Gcolon021 deleted the ALS-6235-Rewrite branch June 7, 2024 15:54
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.

2 participants