FIX: Don't publish notifications to MessageBus for inactive users (#15035)

We are pushing /notification-alert/#{user_id} and /notification/#{user_id}
messages to MessageBus from both PostAlerter and User#publish_notification_state.
This can cause memory issues on large sites with many users. This commit
stems the bleeding by only sending these alert messages if the user
in question has been seen in the last 30 days, which eliminates a large
chunk of users on some sites.
This commit is contained in:
Martin Brennan
2021-11-22 13:38:49 +10:00
committed by GitHub
parent 9015183942
commit 9f8ee8f137
4 changed files with 58 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
require 'rails_helper'
describe User do
let(:user) { Fabricate(:user) }
let(:user) { Fabricate(:user, last_seen_at: 1.day.ago) }
def user_error_message(*keys)
I18n.t(:"activerecord.errors.models.user.attributes.#{keys.join('.')}")
@@ -1921,6 +1921,18 @@ describe User do
expect(message.data[:unread_private_messages]).to eq(2)
expect(message.data[:unread_high_priority_notifications]).to eq(2)
end
it "does not publish to the /notification channel for users who have not been seen in > 30 days" do
notification = Fabricate(:notification, user: user)
notification2 = Fabricate(:notification, user: user, read: true)
user.update(last_seen_at: 31.days.ago)
message = MessageBus.track_publish("/notification/#{user.id}") do
user.publish_notifications_state
end.first
expect(message).to eq(nil)
end
end
describe "silenced?" do