You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am implementing noticed gem and I'd enjoy some advise/feedback considering best practices.
Let's say I have a Discussion model and it has many Posts. When someone posts on a discussion, all the people who have posted on it before should also be notified. I have a NewPostNotification noticed notification class. Use the after_create_commit on the Post model to trigger a job within which I'd loop through records and call NewPostNotification. (I am considering using ActiveJob with sidekiq)
Since noticed gem doesn't support batch notifications (yet), this is what I thought of. Can anyone give some feedback?
# app/jobs/new_post_notification_job.rbclassNewPostNotificationJob < ApplicationJobqueue_as:defaultdefperform(post_id)post=Post.find(post_id)discussion=post.discussion# Loop through users who have posted on the discussiondiscussion.posts.eachdo |previous_post|
user=previous_post.userNewPostNotification.with(post:).deliver_later(user:)endendend
Edit: I see that we can use multiple recipients in deliver_later, this probably solves it for now. But still wonder how this will be if there are thousands of users.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am implementing noticed gem and I'd enjoy some advise/feedback considering best practices.
Let's say I have a
Discussion
model and it has manyPosts
. When someone posts on a discussion, all the people who have posted on it before should also be notified. I have aNewPostNotification
noticed notification class. Use theafter_create_commit
on the Post model to trigger a job within which I'd loop through records and call NewPostNotification. (I am considering using ActiveJob with sidekiq)Since noticed gem doesn't support batch notifications (yet), this is what I thought of. Can anyone give some feedback?
Edit: I see that we can use multiple recipients in deliver_later, this probably solves it for now. But still wonder how this will be if there are thousands of users.
Related:
Beta Was this translation helpful? Give feedback.
All reactions