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

fix: [DHIS2-18459] Re-use obtained maxTeLimit (2.41) #19590

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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.getMaxTeLimit() > 0) {
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.getMaxTeLimit() > 0 ? getLimitClause(params.getMaxTeLimit() + 1) : "")
.append(" ) tecount")
.toString();
}
Expand Down
Loading