Skip to content

Commit

Permalink
WIP - removed dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
luciano-fiandesio committed Dec 18, 2024
1 parent f3cd996 commit ad785bb
Showing 1 changed file with 1 addition and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ public void getEnrollments(EventQueryParams params, Grid grid, int maxLimit) {
String sql;
if (params.isAggregatedEnrollments()) {
sql = getAggregatedEnrollmentsSql(grid.getHeaders(), params);
} else if (!params.getItems().isEmpty() && shouldUseCTE(params)) {
// TODO no longer needed
sql = buildEnrollmentQueryWithCTE(params, params.getItems().get(0));
} else {
sql = buildEnrollmentQueryWithCte2(params);
}
Expand All @@ -171,14 +168,6 @@ public void getEnrollments(EventQueryParams params, Grid grid, int maxLimit) {
}
}

private boolean shouldUseCTE(EventQueryParams params) {
if (params.getItems().isEmpty()) {
return false;
}
QueryItem item = params.getItems().get(0);
return item.hasProgram() && item.hasProgramStage();
}

/**
* Adds enrollments to the given grid based on the given parameters and SQL statement.
*
Expand Down Expand Up @@ -330,7 +319,7 @@ public long getEnrollmentCount(EventQueryParams params) {
withExceptionHandling(
() -> jdbcTemplate.queryForObject(finalSqlValue, Long.class),
params.isMultipleQueries())
.orElse(0l);
.orElse(0L);
}

return count;
Expand Down Expand Up @@ -1182,47 +1171,6 @@ private String resolveOrderByOffset(int offset) {
return "asc";
}

private String buildEnrollmentQueryWithCTE(EventQueryParams params, QueryItem item) {

StringBuilder sql = new StringBuilder();
List<QueryItem> items = params.getItems();

// 1. Build CTEs for each unique program stage + offset combination
sql.append(buildAllRankedEventsCTEs(items));

// 2. Build main query
sql.append("select ");

// 2.1 Add basic columns
sql.append(getBasicSelectColumns());

// 2.2 Add value columns for each item
String valueColumns = buildValueColumns(items);
if (!valueColumns.isEmpty()) {
sql.append(", ").append(valueColumns);
}

// 2.3 Add FROM clause with all necessary joins
sql.append(buildFromClauseWithJoins(params, items));

// 2.4 Add WHERE clause
String whereClause = getWhereClause(params).trim();
if (!whereClause.isEmpty()) {
// Remove any leading "and" and ensure only one "where" keyword
whereClause = whereClause.replaceFirst("^and\\s+", "");
whereClause = whereClause.replaceFirst("^where\\s+", "");
if (!whereClause.isEmpty()) {
sql.append(" where ").append(whereClause);
}
}

// 2.5 Add ORDER BY and paging
sql.append(getSortClause(params));
sql.append(getPagingClause(params, 5000));

return sql.toString();
}

private String buildAllRankedEventsCTEs(List<QueryItem> items) {
StringBuilder ctes = new StringBuilder();
Set<String> processedCombinations = new HashSet<>();
Expand Down

0 comments on commit ad785bb

Please sign in to comment.