diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/cases/repository/CaseRepositoryIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/cases/repository/CaseRepositoryIntTest.java index 4aa8d63da8f..2a8968a6611 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/cases/repository/CaseRepositoryIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/cases/repository/CaseRepositoryIntTest.java @@ -37,7 +37,7 @@ class CaseRepositoryIntTest extends IntegrationBase { private CaseRepository caseRepository; @Test - void findByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_ReturnsResults() { + void findByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_ShouldReturnsResults() { // given caseStub.createAndSaveCourtCase(courtCase -> { courtCase.setRetentionUpdated(true); @@ -69,7 +69,7 @@ void findByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_ReturnsResults() { } @Test - void findIdsByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_caseHasNoAssocaitedCaseRetentionEntity_shouldNotReturn() { + void findIdsByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_ShouldNotReturn_WhenCaseHasNoAssociatedCaseRetentionEntity() { // given caseStub.createAndSaveCourtCase(courtCase -> { courtCase.setRetentionUpdated(true); @@ -82,7 +82,7 @@ void findIdsByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_caseHasNoAssocai } @Test - void findIdsByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_oneCaseHasMultipleRetentionObjects_shouldOnlyReturnIdOnce() { + void findIdsByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_ShouldOnlyReturnIdOnce_WhereOneCaseHasMultipleRetentionObjects() { // given var matchingCase = caseStub.createAndSaveCourtCase(courtCase -> { courtCase.setRetentionUpdated(true); @@ -106,7 +106,7 @@ void findIdsByIsRetentionUpdatedTrueAndRetentionRetriesLessThan_oneCaseHasMultip @Test - void findCasesIdsNeedingCaseDocumentGenerated_ReturnsMatchingCases() { + void findCasesIdsNeedingCaseDocumentGenerated_ShouldReturnsMatchingCases() { // given caseStub.createAndSaveCourtCase(courtCase -> { courtCase.setClosed(true); diff --git a/src/main/java/uk/gov/hmcts/darts/common/repository/CaseRepository.java b/src/main/java/uk/gov/hmcts/darts/common/repository/CaseRepository.java index 2231606a677..b537eac996c 100644 --- a/src/main/java/uk/gov/hmcts/darts/common/repository/CaseRepository.java +++ b/src/main/java/uk/gov/hmcts/darts/common/repository/CaseRepository.java @@ -54,12 +54,12 @@ AND NOT EXISTS (select 1 from CaseRetentionEntity cre """) List findOpenCasesToClose(OffsetDateTime cutoffDate, Limit limit); + // Must have join to case retention to ensure all cases returned have CaseRetentionEntity @Query(""" SELECT distinct cc.id FROM CourtCaseEntity cc - JOIN cc.caseRetentionEntities cr - WHERE cr is not null - AND cc.isRetentionUpdated = true + JOIN cc.caseRetentionEntities cr + WHERE cc.isRetentionUpdated = true AND cc.retentionRetries < :maxRetentionRetries ORDER BY cc.id ASC """) diff --git a/src/main/resources/db/migration/postgres/V1_489__create_new_indexes.sql b/src/main/resources/db/migration/postgres/V1_489__create_new_indexes.sql new file mode 100644 index 00000000000..0750bdb27c3 --- /dev/null +++ b/src/main/resources/db/migration/postgres/V1_489__create_new_indexes.sql @@ -0,0 +1 @@ +CREATE INDEX IF NOT EXISTS cr_rr_idx ON case_retention (retention_retries);