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

Improve the performance by having equal operator instead of LIKE operator when counting total users #480

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,28 @@ private long getTotalUsers(String domainName) throws CharonException {
return totalUsers;
}

private long getTotalUsers(ExpressionNode node, String domainName) throws CharonException {

long totalUsers = 0;
AbstractUserStoreManager secondaryUserStoreManager = null;
if (StringUtils.isNotBlank(domainName)) {
secondaryUserStoreManager = (AbstractUserStoreManager) carbonUM
.getSecondaryUserStoreManager(domainName);
}
try {
if (secondaryUserStoreManager instanceof JDBCUserStoreManager) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if the userstore manager is not an instance of JDBCUserStoreManager? It will return the totalUsers as 0

Copy link
Contributor Author

@Kanapriya Kanapriya Aug 31, 2023

Choose a reason for hiding this comment

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

No, this will return the page size and if the limit for the page size is not defined, then the max number of users returned in the response. That is simply the number of users in the response at that time.

if (node != null && node.getOperation() != null && SCIMCommonConstants.EQ.equals(node.getOperation())) {
totalUsers = secondaryUserStoreManager.countUsersWithClaims(node.getValue(), node.getOperation());
} else {
totalUsers = secondaryUserStoreManager.countUsersWithClaims(USERNAME_CLAIM, SCIMCommonConstants.ANY);
}
}
} catch (org.wso2.carbon.user.core.UserStoreException e) {
throw resolveError(e, "Error while getting total user count in domain: " + domainName);
}
return totalUsers;
}

/**
* Method to decide whether to paginate based on the offset and the limit in the request.
*
Expand Down Expand Up @@ -1408,7 +1430,7 @@ private UsersGetResponse filterUsersBySingleAttribute(ExpressionNode node, Map<S
boolean canCountTotalUserCount = canCountTotalUserCount(userStoreDomainNames);
if (canCountTotalUserCount) {
for (String userStoreDomainName : userStoreDomainNames) {
maxLimit += getTotalUsers(userStoreDomainName);
maxLimit += getTotalUsers(node, userStoreDomainName);
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
<cxf-bundle.version>3.3.7</cxf-bundle.version>
<inbound.auth.oauth.version>6.5.3</inbound.auth.oauth.version>
<commons-collections.version>3.2.0.wso2v1</commons-collections.version>
<carbon.kernel.version>4.9.15</carbon.kernel.version>
<carbon.kernel.version>4.9.18</carbon.kernel.version>
<identity.framework.version>5.25.509</identity.framework.version>
<junit.version>4.13.1</junit.version>
<commons.lang.version>20030203.000129</commons.lang.version>
Expand Down
Loading