From 6cc174ca82d8c4c79c7dc8dd9b25763bc8ee9215 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 23 Jun 2017 16:53:07 +0900 Subject: [PATCH] PERF: Fetch users in batches in grant anniversary badge job. --- app/jobs/scheduled/grant_anniversary_badges.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/jobs/scheduled/grant_anniversary_badges.rb b/app/jobs/scheduled/grant_anniversary_badges.rb index e5e3287cb03..5c01c53888e 100644 --- a/app/jobs/scheduled/grant_anniversary_badges.rb +++ b/app/jobs/scheduled/grant_anniversary_badges.rb @@ -32,13 +32,12 @@ module Jobs SQL badge = Badge.find(Badge::Anniversary) - user_ids = results.map {|r| r['user_id'].to_i } + user_ids = results.map { |r| r['user_id'].to_i } - User.where(id: user_ids).each do |user| + User.where(id: user_ids).find_each do |user| BadgeGranter.grant(badge, user, created_at: end_date) end end end end -