Skip to content

Commit

Permalink
Merge pull request #480 from Kanapriya/fix_performance_issue
Browse files Browse the repository at this point in the history
Improve the performance by having equal operator instead of LIKE operator when counting total users
  • Loading branch information
Kanapriya committed Nov 22, 2023
2 parents 3bda35d + 5477f7a commit 81afde1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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) {
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

0 comments on commit 81afde1

Please sign in to comment.