From 3e1710c8fcc5bfa2317840431f8f0689ba0ae681 Mon Sep 17 00:00:00 2001 From: Olivier Fuxet Date: Thu, 21 Nov 2024 11:20:34 +0100 Subject: [PATCH] Do not notify about a GFI that has already been notified --- .../it/api/feature/GoodFirstIssueCreatedNotifierJobIT.java | 6 ++++++ .../adapter/repository/GithubIssueViewRepository.java | 2 ++ .../db/changelog/changelogs/00000028_add_indexes.sql | 5 +++++ .../main/resources/db/changelog/db.changelog-master.yaml | 2 ++ 4 files changed, 15 insertions(+) create mode 100644 infrastructure/postgres-adapter/src/main/resources/db/changelog/changelogs/00000028_add_indexes.sql diff --git a/bootstrap/src/test/java/onlydust/com/marketplace/api/it/api/feature/GoodFirstIssueCreatedNotifierJobIT.java b/bootstrap/src/test/java/onlydust/com/marketplace/api/it/api/feature/GoodFirstIssueCreatedNotifierJobIT.java index 3553df328..e5739ab76 100644 --- a/bootstrap/src/test/java/onlydust/com/marketplace/api/it/api/feature/GoodFirstIssueCreatedNotifierJobIT.java +++ b/bootstrap/src/test/java/onlydust/com/marketplace/api/it/api/feature/GoodFirstIssueCreatedNotifierJobIT.java @@ -132,5 +132,11 @@ void should_notify_users_on_new_good_first_issues() throws InterruptedException .withRequestBody(matchingJsonPath("$.subject", equalTo("New good first issue")))); customerIOWireMockServer.verify(2, postRequestedFor(urlEqualTo("/send/email"))); + customerIOWireMockServer.resetAll(); + + // Check that notification for a single issue is sent only once + goodFirstIssueCreatedNotifierJob.run(); + Thread.sleep(1000L); + customerIOWireMockServer.verify(0, postRequestedFor(urlEqualTo("/send/email"))); } } diff --git a/infrastructure/postgres-adapter/src/main/java/onlydust/com/marketplace/api/postgres/adapter/repository/GithubIssueViewRepository.java b/infrastructure/postgres-adapter/src/main/java/onlydust/com/marketplace/api/postgres/adapter/repository/GithubIssueViewRepository.java index f0be7b5e4..30badd3a6 100644 --- a/infrastructure/postgres-adapter/src/main/java/onlydust/com/marketplace/api/postgres/adapter/repository/GithubIssueViewRepository.java +++ b/infrastructure/postgres-adapter/src/main/java/onlydust/com/marketplace/api/postgres/adapter/repository/GithubIssueViewRepository.java @@ -31,6 +31,8 @@ public interface GithubIssueViewRepository extends Repository'notification'->>'@type' = 'GoodFirstIssueCreated' + AND cast(n.data->'notification'->'issue'->>'id' as bigint) = gi.id) """, nativeQuery = true) List findAllGoodFirstIssuesCreatedSince5Minutes(ZonedDateTime now, String timezone); diff --git a/infrastructure/postgres-adapter/src/main/resources/db/changelog/changelogs/00000028_add_indexes.sql b/infrastructure/postgres-adapter/src/main/resources/db/changelog/changelogs/00000028_add_indexes.sql new file mode 100644 index 000000000..e8ad773b0 --- /dev/null +++ b/infrastructure/postgres-adapter/src/main/resources/db/changelog/changelogs/00000028_add_indexes.sql @@ -0,0 +1,5 @@ +create index if not exists notifications_data_notification_type_index + on iam.notifications ((data -> 'notification' ->> '@type')); + +create index if not exists notifications_data_notification_issue_id_index + on iam.notifications ((cast(data -> 'notification' -> 'issue' ->> 'id' as bigint))); diff --git a/infrastructure/postgres-adapter/src/main/resources/db/changelog/db.changelog-master.yaml b/infrastructure/postgres-adapter/src/main/resources/db/changelog/db.changelog-master.yaml index 9c14d9b9e..254d15dee 100644 --- a/infrastructure/postgres-adapter/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/infrastructure/postgres-adapter/src/main/resources/db/changelog/db.changelog-master.yaml @@ -49,3 +49,5 @@ databaseChangeLog: file: db/changelog/changelogs/00000026_add_missing_indexes.sql - include: file: db/changelog/changelogs/00000027_restore_indexes.sql + - include: + file: db/changelog/changelogs/00000028_add_indexes.sql