From b0b9d3defe0d980e166e2d621cfb8c44e51eb914 Mon Sep 17 00:00:00 2001 From: Dave King Date: Fri, 29 Apr 2022 12:07:40 +0100 Subject: [PATCH 1/4] removing sort from deleteByTypeAndClient and let db return in whatever order --- .../idempotence4j/mariadb/JdbcMariaDbActionRepository.java | 1 - .../idempotence4j/postgres/JdbcPostgresActionRepository.java | 1 - 2 files changed, 2 deletions(-) diff --git a/idempotence4j-mariadb/src/main/java/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepository.java b/idempotence4j-mariadb/src/main/java/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepository.java index f97acaf..b1bd0de 100644 --- a/idempotence4j-mariadb/src/main/java/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepository.java +++ b/idempotence4j-mariadb/src/main/java/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepository.java @@ -137,7 +137,6 @@ public int[] deleteByIds(List actionIdList) { "DELETE FROM idempotent_action " + "WHERE type = :type " + " AND client = :client " + - "ORDER BY created_at ASC " + "LIMIT :limit"; private final static String DELETE_BY_ACTION_ID_SQL = diff --git a/idempotence4j-postgres/src/main/java/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepository.java b/idempotence4j-postgres/src/main/java/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepository.java index d56a0e9..ad24d47 100644 --- a/idempotence4j-postgres/src/main/java/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepository.java +++ b/idempotence4j-postgres/src/main/java/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepository.java @@ -148,7 +148,6 @@ public int[] deleteByIds(List actionIds) { "WHERE " + "type = :type " + "AND client = :client " + - "ORDER BY created_at ASC " + "LIMIT :limit"; private final static String DELETE_BY_ACTION_ID_SQL = From 07100b2c7f8db67f25ec9aafcd36809224c3a714 Mon Sep 17 00:00:00 2001 From: Dave King Date: Fri, 29 Apr 2022 12:08:05 +0100 Subject: [PATCH 2/4] add index for type and client on idempotent_action --- ...V20220429110000__add_idempotent_action_type_client_index.sql | 2 ++ ...V20220429110000__add_idempotent_action_type_client_index.sql | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 idempotence4j-mariadb/src/main/resources/db/idempotence4j/mariadb/V20220429110000__add_idempotent_action_type_client_index.sql create mode 100644 idempotence4j-postgres/src/main/resources/db/idempotence4j/postgres/V20220429110000__add_idempotent_action_type_client_index.sql diff --git a/idempotence4j-mariadb/src/main/resources/db/idempotence4j/mariadb/V20220429110000__add_idempotent_action_type_client_index.sql b/idempotence4j-mariadb/src/main/resources/db/idempotence4j/mariadb/V20220429110000__add_idempotent_action_type_client_index.sql new file mode 100644 index 0000000..231c887 --- /dev/null +++ b/idempotence4j-mariadb/src/main/resources/db/idempotence4j/mariadb/V20220429110000__add_idempotent_action_type_client_index.sql @@ -0,0 +1,2 @@ +CREATE INDEX IF NOT EXISTS IDX_IDEMPOTENT_ACTION_TYPE_CLIENT + ON idempotent_action (type, client); diff --git a/idempotence4j-postgres/src/main/resources/db/idempotence4j/postgres/V20220429110000__add_idempotent_action_type_client_index.sql b/idempotence4j-postgres/src/main/resources/db/idempotence4j/postgres/V20220429110000__add_idempotent_action_type_client_index.sql new file mode 100644 index 0000000..864c8e2 --- /dev/null +++ b/idempotence4j-postgres/src/main/resources/db/idempotence4j/postgres/V20220429110000__add_idempotent_action_type_client_index.sql @@ -0,0 +1,2 @@ +CREATE INDEX CONCURRENTLY IF NOT EXISTS IDX_IDEMPOTENT_ACTION_TYPE_CLIENT + ON idempotent_action (type, client); From 565e59ecc76c6f4fe658a341af53a5617f913eed Mon Sep 17 00:00:00 2001 From: Dave King Date: Fri, 29 Apr 2022 12:15:49 +0100 Subject: [PATCH 3/4] update CHANGELOG.md and version --- CHANGELOG.md | 4 ++++ gradle.properties | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 327c406..9ad8eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 1.8.0 - 2022-04-29 +- Add index definition for `deleteByTypeAndClient` +- `deleteByTypeAndClient` is now more performant without sorting in the query + ## 1.7.0 - 2022-04-19 - `deleteOlderThan` method on `ActionRepository` now forces use of a primitive for batch size. - Begin returning the number of rows deleted from deletion methods in `ActionRepository` diff --git a/gradle.properties b/gradle.properties index fd898e4..8891e47 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.transferwise.idempotence4j -version=1.7.0 +version=1.8.0 From 131eff163490d5c467422b0a9b1828581b783fa0 Mon Sep 17 00:00:00 2001 From: Dave King Date: Fri, 29 Apr 2022 12:33:07 +0100 Subject: [PATCH 4/4] fix tests --- .../JdbcMariaDbActionRepositoryIntegrationTest.groovy | 5 +---- .../JdbcPostgresActionRepositoryIntegrationTest.groovy | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/idempotence4j-mariadb/src/test-integration/groovy/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepositoryIntegrationTest.groovy b/idempotence4j-mariadb/src/test-integration/groovy/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepositoryIntegrationTest.groovy index 8f57483..b7298b0 100644 --- a/idempotence4j-mariadb/src/test-integration/groovy/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepositoryIntegrationTest.groovy +++ b/idempotence4j-mariadb/src/test-integration/groovy/com/transferwise/idempotence4j/mariadb/JdbcMariaDbActionRepositoryIntegrationTest.groovy @@ -104,14 +104,11 @@ class JdbcMariaDbActionRepositoryIntegrationTest extends IntegrationTest { } and: List actionIds = actions.each { it -> repository.insertOrGet(it) } .collect({ it.actionId }) - def firstHalfActionIds = actionIds.dropRight(actions.size() / 2 as int) - def lastHalfActionIds = actionIds.drop(actions.size() / 2 as int) when: int firstDeletionCount = repository.deleteByTypeAndClient(TYPE, CLIENT, 5) then: firstDeletionCount == 5 - firstHalfActionIds.each { ActionId it -> assert repository.find(it).isEmpty() } - lastHalfActionIds.each { ActionId it -> assert !repository.find(it).isEmpty() } + actionIds.findAll { repository.find(it).isEmpty() }.size() == 5 when: int secondDeletionCount = repository.deleteByTypeAndClient(TYPE, CLIENT, 5) then: diff --git a/idempotence4j-postgres/src/test-integration/groovy/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepositoryIntegrationTest.groovy b/idempotence4j-postgres/src/test-integration/groovy/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepositoryIntegrationTest.groovy index 823c75e..ba89b39 100644 --- a/idempotence4j-postgres/src/test-integration/groovy/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepositoryIntegrationTest.groovy +++ b/idempotence4j-postgres/src/test-integration/groovy/com/transferwise/idempotence4j/postgres/JdbcPostgresActionRepositoryIntegrationTest.groovy @@ -106,14 +106,11 @@ class JdbcPostgresActionRepositoryIntegrationTest extends IntegrationTest { } and: List actionIds = actions.each { it -> repository.insertOrGet(it) } .collect({ it.actionId }) - def firstHalfActionIds = actionIds.dropRight(actions.size() / 2 as int) - def lastHalfActionIds = actionIds.drop(actions.size() / 2 as int) when: int firstDeletionCount = repository.deleteByTypeAndClient(TYPE, CLIENT, 5) then: firstDeletionCount == 5 - firstHalfActionIds.each { ActionId it -> assert repository.find(it).isEmpty() } - lastHalfActionIds.each { ActionId it -> assert !repository.find(it).isEmpty() } + actionIds.findAll { repository.find(it).isEmpty() }.size() == 5 when: int secondDeletionCount = repository.deleteByTypeAndClient(TYPE, CLIENT, 5) then: