FIX: Fixes to grant new user of the month badge

This commit is contained in:
Robin Ward 2017-05-24 11:35:59 -04:00
parent f12490eae0
commit b78b010757

View File

@ -2,7 +2,7 @@ require 'badge_granter'
module Jobs
class GrantNewUserOfTheMonthBadges < Jobs::Scheduled
every 1.month
every 1.day
MAX_AWARDED = 2
@ -33,6 +33,9 @@ module Jobs
def scores
scores = {}
current_owners = UserBadge.where(badge_id: Badge::NewUserOfTheMonth).pluck(:user_id)
current_owners = [-1] if current_owners.blank?
# Find recent accounts and come up with a score based on how many likes they
# received, based on how much they posted and how old the accounts of the people
# who voted on them are.
@ -62,7 +65,8 @@ module Jobs
u.id > 0 AND
NOT(u.admin) AND
NOT(u.moderator) AND
u.created_at >= CURRENT_TIMESTAMP - '1 month'::INTERVAL
u.created_at >= CURRENT_TIMESTAMP - '1 month'::INTERVAL AND
u.id NOT IN (#{current_owners.join(',')})
GROUP BY u.id
HAVING COUNT(DISTINCT p.id) > 1
AND COUNT(DISTINCT p.topic_id) > 1