Skip to content

Commit

Permalink
fix: [DHIS2-18459] Re-use obtained maxTeLimit (2.41) (#19590)
Browse files Browse the repository at this point in the history
* fix: [DHIS2-18459] Re-use obtained maxTeLimit (2.41)

* Apply spotless

* Add hasMaxTeLimit convenience method

* Remove this to make it consistent
  • Loading branch information
ameenhere authored Jan 3, 2025
1 parent ce07f13 commit 2fb6a08
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ public boolean hasTrackedEntityType() {
return trackedEntityType != null;
}

/** Indicates whether this parameters specifies a max TE limit. */
public boolean hasMaxTeLimit() {
return maxTeLimit > 0;
}

/** Indicates whether this parameters is of the given organisation unit mode. */
public boolean isOrganisationUnitMode(OrganisationUnitSelectionMode mode) {
return orgUnitMode != null && orgUnitMode.equals(mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,16 @@ public void validateSearchScope(TrackedEntityQueryParams params, boolean isGridS
}
}

checkIfMaxTeiLimitIsReached(params, maxTeiLimit);
params.setMaxTeLimit(maxTeiLimit);
checkIfMaxTeiLimitIsReached(params);
}
}

private void checkIfMaxTeiLimitIsReached(TrackedEntityQueryParams params, int maxTeiLimit) {
if (maxTeiLimit > 0) {
private void checkIfMaxTeiLimitIsReached(TrackedEntityQueryParams params) {
if (params.hasMaxTeLimit()) {
int teCount = trackedEntityStore.getTrackedEntityCountForGridWithMaxTeiLimit(params);

if (teCount > maxTeiLimit) {
if (teCount > params.getMaxTeLimit()) {
throw new IllegalQueryException("maxteicountreached");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,14 @@ private String getCountQuery(TrackedEntityQueryParams params) {
* @return a count SQL query
*/
private String getCountQueryWithMaxTeiLimit(TrackedEntityQueryParams params) {
boolean hasMaxTeiCountToReturn =
params.hasProgram() && params.getProgram().hasMaxTeiCountToReturn();
return new StringBuilder()
.append(getQueryCountSelect(params))
.append(getQuerySelect(params))
.append("FROM ")
.append(getFromSubQuery(params, true, true))
.append(getQueryRelatedTables(params))
.append(getQueryGroupBy(params))
.append(
hasMaxTeiCountToReturn
? getLimitClause(params.getProgram().getMaxTeiCountToReturn() + 1)
: "")
.append(params.hasMaxTeLimit() ? getLimitClause(params.getMaxTeLimit() + 1) : "")
.append(" ) tecount")
.toString();
}
Expand Down

0 comments on commit 2fb6a08

Please sign in to comment.