mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: limit number of notifications per user to 10,000
Introduces a new site setting `max_notifications_per_user`. Out-of-the-box this is set to 10,000. If a user exceeds this number of notifications, we will delete the oldest notifications keeping only 10,000. To disable this safeguard set the setting to 0. Enforcement happens weekly. This is in place to protect the system from pathological states where a single user has enormous amounts of notifications causing various queries to time out. In practice nobody looks back more than a few hundred notifications.
This commit is contained in:
@@ -414,4 +414,26 @@ describe Notification do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "purge_old!" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:notification1) { Fabricate(:notification, user: user) }
|
||||
fab!(:notification2) { Fabricate(:notification, user: user) }
|
||||
fab!(:notification3) { Fabricate(:notification, user: user) }
|
||||
fab!(:notification4) { Fabricate(:notification, user: user) }
|
||||
|
||||
it "does nothing if set to 0" do
|
||||
SiteSetting.max_notifications_per_user = 0
|
||||
Notification.purge_old!
|
||||
|
||||
expect(Notification.where(user_id: user.id).count).to eq(4)
|
||||
end
|
||||
|
||||
it "correctly limits" do
|
||||
SiteSetting.max_notifications_per_user = 2
|
||||
Notification.purge_old!
|
||||
|
||||
expect(Notification.where(user_id: user.id).pluck(:id)).to contain_exactly(notification4.id, notification3.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user