From 2aad91d4a29a5196cc40f26e86e6e77b1a8f6935 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 24 May 2018 10:02:26 +0800 Subject: [PATCH] PERF: Don't bloat the Sidekiq queue with `Jobs::SendPushNotification`. --- app/services/post_alerter.rb | 4 ++++ config/initializers/100-push-notifications.rb | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index d5539e34c6f..240d817c590 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -415,6 +415,10 @@ class PostAlerter end def push_notification(user, payload) + if user.push_subscriptions.exists? + Jobs.enqueue(:send_push_notification, user_id: user.id, payload: payload) + end + if SiteSetting.allow_user_api_key_scopes.split("|").include?("push") && SiteSetting.allowed_user_api_push_urls.present? clients = user.user_api_keys .where("('push' = ANY(scopes) OR 'notifications' = ANY(scopes)) AND push_url IS NOT NULL AND position(push_url in ?) > 0 AND revoked_at IS NULL", diff --git a/config/initializers/100-push-notifications.rb b/config/initializers/100-push-notifications.rb index 8cb0542cab8..50f580c3883 100644 --- a/config/initializers/100-push-notifications.rb +++ b/config/initializers/100-push-notifications.rb @@ -8,10 +8,6 @@ end SiteSetting.vapid_public_key_bytes = Base64.urlsafe_decode64(SiteSetting.vapid_public_key).bytes.join("|") -DiscourseEvent.on(:post_notification_alert) do |user, payload| - Jobs.enqueue(:send_push_notification, user_id: user.id, payload: payload) -end - DiscourseEvent.on(:user_logged_out) do |user| PushNotificationPusher.clear_subscriptions(user) end