From 1db02f355cef9b7038771e344c331decc4960240 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Tue, 11 Jan 2022 14:09:11 -0600 Subject: [PATCH] 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 --- .../broadcasts/send_welcome_notifications_worker.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/workers/broadcasts/send_welcome_notifications_worker.rb b/app/workers/broadcasts/send_welcome_notifications_worker.rb index 9327b9746..91fca4192 100644 --- a/app/workers/broadcasts/send_welcome_notifications_worker.rb +++ b/app/workers/broadcasts/send_welcome_notifications_worker.rb @@ -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