-
Notifications
You must be signed in to change notification settings - Fork 31
Cme 206 performance #2889
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
base: master
Are you sure you want to change the base?
Cme 206 performance #2889
Changes from all commits
d9740e2
f01149c
bdc5d43
6c2ab39
c01de4d
8fa4f6c
939252b
976650c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package uk.gov.hmcts.ccd.data.casedetails.search; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| import jakarta.persistence.Query; | ||
|
|
||
| public class DateRangeMetaDataCriterion extends MetaDataCriterion { | ||
|
|
||
| private static final String FROM_SUFFIX = "_from"; | ||
| private static final String TO_SUFFIX = "_to"; | ||
|
|
||
| private final LocalDate soughtDate; | ||
|
|
||
| public DateRangeMetaDataCriterion(String field, LocalDate soughtDate) { | ||
| super(field, soughtDate.toString()); | ||
| this.soughtDate = soughtDate; | ||
| } | ||
|
|
||
| @Override | ||
| public String buildClauseString(String operation) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replacing date(column) = ? with a half-open timestamp range keeps the predicate sargable, so Postgres can use the existing timestamp indexes. |
||
| String parameterId = buildParameterId(); | ||
| return getField() + " >= " + PARAM_PREFIX + parameterId + FROM_SUFFIX | ||
| + " AND " + getField() + " < " + PARAM_PREFIX + parameterId + TO_SUFFIX; | ||
| } | ||
|
|
||
| @Override | ||
| public void bindParameters(Query query) { | ||
| String parameterId = buildParameterId(); | ||
| query.setParameter(parameterId + FROM_SUFFIX, soughtDate.atStartOfDay()); | ||
| query.setParameter(parameterId + TO_SUFFIX, soughtDate.plusDays(1).atStartOfDay()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,9 +76,7 @@ public Optional<Query> build(MetaData metadata, Map<String, String> params, bool | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| String sortClause = sortOrderQueryBuilder.buildSortOrderClause(metadata); | ||
| String queryToFormat = isCountQuery ? MAIN_COUNT_QUERY : MAIN_QUERY; | ||
| String queryString = String.format(queryToFormat, whereClausePart, sortClause); | ||
| String queryString = buildQueryString(isCountQuery, whereClausePart, metadata); | ||
|
|
||
| Query query; | ||
| if (isCountQuery) { | ||
|
|
@@ -133,7 +131,16 @@ private String addUserCaseStateAccessClause(MetaData metadata, Map<String, Objec | |
| } | ||
|
|
||
| private void addParameters(final Query query, List<Criterion> criteria) { | ||
| criteria.forEach(criterion -> query.setParameter(criterion.buildParameterId(), criterion.getSoughtValue())); | ||
| criteria.forEach(criterion -> criterion.bindParameters(query)); | ||
| } | ||
|
|
||
| private String buildQueryString(boolean isCountQuery, String whereClausePart, MetaData metadata) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. count queries no longer build an unused sort clause, avoiding unnecessary work |
||
| if (isCountQuery) { | ||
| return String.format(MAIN_COUNT_QUERY, whereClausePart); | ||
| } | ||
|
|
||
| String sortClause = sortOrderQueryBuilder.buildSortOrderClause(metadata); | ||
| return String.format(MAIN_QUERY, whereClausePart, sortClause); | ||
| } | ||
|
|
||
| private String toClauses(final List<Criterion> criteria) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ spring.datasource.hikari.connection-timeout=${DATA_STORE_DB_CONNECTION_TIMEOUT:4 | |
| spring.datasource.hikari.idle-timeout=${DATA_STORE_DB_IDLE_TIMEOUT:300000} | ||
| spring.datasource.hikari.minimum-idle=${DATA_STORE_DB_MIN_IDLE:8} | ||
| spring.datasource.hikari.maximum-pool-size=${DATA_STORE_DB_MAX_POOL_SIZE:16} | ||
| # WARNING: disabling Open Session in View means lazy JPA associations must be loaded/mapped inside service or | ||
| # repository transactions. Accessing lazy associations during response serialization can cause LazyInitializationException. | ||
| spring.jpa.open-in-view=false | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slight;y dangerous so could remove and merge in a future pr, but good best practice change |
||
| # Disable feature detection to avoid the java.sql.SQLFeatureNotSupportedException | ||
| # Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented. | ||
| spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove subquery, and sort instead of using min