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

Issue 1931: Pagination not working properly for combined filters list. #1932

Merged
merged 4 commits into from
May 10, 2024
Merged
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 @@ -449,6 +449,7 @@ public int compare(SubmissionListColumn svc1, SubmissionListColumn svc2) {
sqlAliasBuilders.add("s.id");

int n = 0;
int totalFieldValueConditions = 0;

for (SubmissionListColumn submissionListColumn : allSubmissionListColumns) {

Expand Down Expand Up @@ -552,6 +553,7 @@ public int compare(SubmissionListColumn svc1, SubmissionListColumn svc2) {
}

if (sqlBuilder.length() > 0) {
totalFieldValueConditions++;
sqlWhereBuilderList.add(sqlBuilder);

if (!sqlCountWherePredicate.containsKey(predicateId)) {
Expand Down Expand Up @@ -942,7 +944,6 @@ public int compare(SubmissionListColumn svc1, SubmissionListColumn svc2) {
});
sqlSelectBuilder.setLength(sqlSelectBuilder.length() - 2);
sqlSelectBuilder.append(" FROM submission s");
sqlCountSelectBuilder.insert(0, "SELECT COUNT(DISTINCT s.id) FROM submission s");

// if ordering, complete order by clause and strip the tailing comma
if (sqlOrderBysBuilder.length() > 0) {
Expand Down Expand Up @@ -1036,7 +1037,14 @@ public int compare(SubmissionListColumn svc1, SubmissionListColumn svc2) {
}

String sqlQuery = sqlSelectBuilder.toString() + sqlJoinsBuilder.toString() + sqlBuilder.toString();
String sqlCountQuery = sqlCountSelectBuilder.toString();
String sqlCountQuery = "SELECT COUNT(DISTINCT s.id) FROM submission s";

// Use count query optimization only when there are fewer than 2 field values in the where clause.
if (totalFieldValueConditions > 1) {
sqlCountQuery += sqlJoinsBuilder.toString() + sqlBuilder.toString();
} else {
sqlCountQuery += sqlCountSelectBuilder.toString();
}

if (pageable != null) {
// determine the offset and limit of the query
Expand Down
Loading