Skip to content

Commit

Permalink
Merge pull request #2982 from bcgov/current_observation_grid_filters
Browse files Browse the repository at this point in the history
make grid filters use materialized views for current positive or nega…
  • Loading branch information
micheal-w-wells authored Nov 21, 2023
2 parents 708b38b + bc3a731 commit b18631d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions api/src/queries/activity-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ LEFT JOIN

sqlStatement.append(SQL` where 1 = 1`);

if(lean) {
sqlStatement.append(SQL` and a.activity_incoming_data_id > 36345`)
if (lean) {
sqlStatement.append(SQL` and a.activity_incoming_data_id > 36345`);
}

if (searchCriteria.activity_type && searchCriteria.activity_type.length) {
Expand Down Expand Up @@ -552,37 +552,37 @@ LEFT JOIN
}
if (gridFilters.current_positive) {
sqlStatement.append(
SQL` AND (SELECT LOWER(string_agg(invasive_plant, ', ')) FROM current_positive_observations cpo WHERE cpo.activity_incoming_data_id = a.activity_incoming_data_id) LIKE '%'||`
SQL` AND (SELECT LOWER(string_agg(invasive_plant, ', ')) FROM current_positive_observations_materialized cpo WHERE cpo.activity_incoming_data_id = a.activity_incoming_data_id) LIKE '%'||`
);
sqlStatement.append(SQL`LOWER(${gridFilters.current_positive})`);
sqlStatement.append(SQL`||'%'`);
}
if (gridFilters.current_negative) {
sqlStatement.append(
SQL` AND (SELECT LOWER(string_agg(invasive_plant, ', ')) FROM current_negative_observations cno WHERE cno.activity_incoming_data_id = a.activity_incoming_data_id) LIKE '%'||`
SQL` AND (SELECT LOWER(string_agg(invasive_plant, ', ')) FROM current_negative_observations_materialized cno WHERE cno.activity_incoming_data_id = a.activity_incoming_data_id) LIKE '%'||`
);
sqlStatement.append(SQL`LOWER(${gridFilters.current_negative})`);
sqlStatement.append(SQL`||'%'`);
}
if (gridFilters.has_current_positive) {
if ('yes'.includes(gridFilters.has_current_positive.toLowerCase())) {
sqlStatement.append(
SQL` AND EXISTS(SELECT 1 FROM current_positive_observations cpo WHERE cpo.activity_incoming_data_id = a.activity_incoming_data_id)`
SQL` AND EXISTS(SELECT 1 FROM current_positive_observations_materialized cpo WHERE cpo.activity_incoming_data_id = a.activity_incoming_data_id)`
);
} else if ('no'.includes(gridFilters.has_current_positive.toLowerCase())) {
sqlStatement.append(
SQL` AND NOT EXISTS(SELECT 1 FROM current_positive_observations cpo WHERE cpo.activity_incoming_data_id = a.activity_incoming_data_id)`
SQL` AND NOT EXISTS(SELECT 1 FROM current_positive_observations_materialized cpo WHERE cpo.activity_incoming_data_id = a.activity_incoming_data_id)`
);
}
}
if (gridFilters.has_current_negative) {
if ('yes'.includes(gridFilters.has_current_negative.toLowerCase())) {
sqlStatement.append(
SQL` AND EXISTS(SELECT 1 FROM current_negative_observations cno WHERE cno.activity_incoming_data_id = a.activity_incoming_data_id)`
SQL` AND EXISTS(SELECT 1 FROM current_negative_observations_materialized cno WHERE cno.activity_incoming_data_id = a.activity_incoming_data_id)`
);
} else if ('no'.includes(gridFilters.has_current_negative.toLowerCase())) {
sqlStatement.append(
SQL` AND NOT EXISTS(SELECT 1 FROM current_negative_observations cno WHERE cno.activity_incoming_data_id = a.activity_incoming_data_id)`
SQL` AND NOT EXISTS(SELECT 1 FROM current_negative_observations_materialized cno WHERE cno.activity_incoming_data_id = a.activity_incoming_data_id)`
);
}
}
Expand Down

0 comments on commit b18631d

Please sign in to comment.