Simplify and label date calculation (#16052)

* Name the created after timestamp and remove temporary variables

The logic used to calculate the live at time, the week ago time, then
compare them to find the more recent value.

Move all of this logic to a method (there's a guard to exit if
the setting is nil, so this should be safe).

* Mark method private

This is not part of the public api (for workers, this should be
`#perform` alone). Mark it private
This commit is contained in:
Daniel Uber 2022-01-11 14:09:11 -06:00 committed by GitHub
parent 7dc59eb4bf
commit 1db02f355c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,12 +10,14 @@ module Broadcasts
# and will ultimately be superseded by 7.days.ago when it's larger than feature_live_date.
return unless Settings::General.welcome_notifications_live_at
notifications_live_at = Settings::General.welcome_notifications_live_at
week_ago = 7.days.ago
latest_date = notifications_live_at > week_ago ? notifications_live_at : week_ago
User.select(:id).where("created_at > ?", latest_date).find_each do |user|
User.select(:id).where("created_at > ?", created_after).find_each do |user|
Broadcasts::WelcomeNotification::Generator.call(user.id)
end
end
def created_after
[Settings::General.welcome_notifications_live_at, 7.days.ago].max
end
private :created_after
end
end