PERF: Don't bloat the Sidekiq queue with `Jobs::SendPushNotification`.

This commit is contained in:
Guo Xiang Tan 2018-05-24 10:02:26 +08:00
parent be49da9105
commit 2aad91d4a2
2 changed files with 4 additions and 4 deletions

View File

@ -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",

View File

@ -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