PERF: Terminate scheduled job earlier if badge is not enabled.

This commit is contained in:
Guo Xiang Tan 2017-06-26 10:13:58 +09:00
parent 69b2d64334
commit 1ab60d83df

View File

@ -4,6 +4,8 @@ module Jobs
def execute(args)
return unless SiteSetting.enable_badges?
badge = Badge.find_by(id: Badge::Anniversary, enabled: true)
return unless badge
start_date = args[:start_date] || 1.year.ago
end_date = start_date + 1.year
@ -31,7 +33,6 @@ module Jobs
HAVING COUNT(p.id) > 0 AND COUNT(ub.id) = 0
SQL
badge = Badge.find(Badge::Anniversary)
user_ids = results.map { |r| r['user_id'].to_i }
User.where(id: user_ids).find_each do |user|