Skip to content

Commit

Permalink
Merge pull request #1932 from TexasDigitalLibrary/1931-pagination_emb…
Browse files Browse the repository at this point in the history
…argo_graduation

Issue 1931: Pagination not working properly for combined filters list.
  • Loading branch information
smutniak authored May 10, 2024
2 parents b506740 + 731a685 commit 9bc6886
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 9bc6886

Please sign in to comment.