Skip to content

feat: add notification deduplication trigger #14172

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

Merged
merged 3 commits into from
Aug 21, 2024
Merged

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Aug 5, 2024

Closes coder/internal#26

Maintains a deduplication hash for each notification_message entry on insert/update to prevent identical notifications from being enqueued on the same day.

I plumbed in coder/quartz to help manipulate time to make the TestNotificationDuplicates simple and readable.

@dannykopping dannykopping marked this pull request as ready for review August 5, 2024 18:25
@@ -13,14 +13,15 @@ WHERE nt.id = @notification_template_id
AND u.id = @user_id;

-- name: EnqueueNotificationMessage :exec
INSERT INTO notification_messages (id, notification_template_id, user_id, method, payload, targets, created_by)
INSERT INTO notification_messages (id, notification_template_id, user_id, method, payload, targets, created_by, created_at)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added created_at to be passed in to make the dedupe hash testable by using Quartz to advance the clock.

Signed-off-by: Danny Kopping <danny@coder.com>
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagged some stuff but looks pretty straight-forward to me, approved.

@github-actions github-actions bot added the stale This issue is like stale bread. label Aug 14, 2024
@github-actions github-actions bot closed this Aug 18, 2024
@dannykopping dannykopping reopened this Aug 19, 2024
@github-actions github-actions bot removed the stale This issue is like stale bread. label Aug 20, 2024
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock; previous comments still hold.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM 👍🏻

@@ -13,6 +13,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/quartz"

"github.com/coder/serpent"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of import grouping, this is the job of the tooling tbh (and it's failing), so up to you if you want to fix it 😄. (There are actually a few more of these too but I'll leave those uncommented.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this for now; we need the tooling to be updated as you suggest.
Thanks for pointing this out though

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@dannykopping dannykopping merged commit 9c8c6a9 into main Aug 21, 2024
28 checks passed
@dannykopping dannykopping deleted the dk/notif-dedupe branch August 21, 2024 09:18
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhancement: prevent notifications with identical content from being sent for recurring events
3 participants