mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
Since we have been using the upcoming change system
more heavily, we noticed that notifications for available changes
(i.e. changes that have been added at promotion status - 1 OR
changes that recently reached promotion status - 1) are crowding
the admin's notifications a lot.
To address this, we already allowed admins to opt out of these
in 0c46a2e805 . However, we also
want to reduce the cadence of these notifications for admins who do want
to opt out completely.
This commit changes upcoming change available notifications to be
collected & sent in a weekly job, rather than in the job that runs
every 20 minutes & logs added/status changed events.
This weekly job will also handle consolidating existing unread upcoming
change available notifications, and making sure that we do not send
N new notifications per change when an admin has no existing unread
notification.
Upcoming change promoted notifications will still happen "instantly"
33 lines
1 KiB
Ruby
Vendored
33 lines
1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
# Intended to be called from UpcomingChanges::Track service,
|
|
# not standalone.
|
|
#
|
|
# Look at UpcomingChangeEvent to get all event_type: added (0) events:
|
|
# * Compare with SiteSetting.upcoming_change_site_settings to see if there are any missing
|
|
# * If so, create an `added` event for the added changes
|
|
#
|
|
# Admins will be notified about newly available upcoming changes
|
|
# on a weekly basis via Jobs::NotifyAdminsOfAvailableUpcomingChanges
|
|
class UpcomingChanges::Action::TrackAddedChanges < Service::ActionBase
|
|
# Every admin user that are not bots
|
|
option :all_admins
|
|
|
|
def call
|
|
added_changes = []
|
|
|
|
(SiteSetting.upcoming_change_site_settings - previously_added_changes).each do |change_name|
|
|
added_changes << change_name
|
|
UpcomingChangeEvent.create!(event_type: :added, upcoming_change_name: change_name)
|
|
end
|
|
|
|
added_changes
|
|
end
|
|
|
|
private
|
|
|
|
def previously_added_changes
|
|
@previously_added_changes ||=
|
|
UpcomingChangeEvent.added.pluck(:upcoming_change_name).uniq.map(&:to_sym)
|
|
end
|
|
end
|