diff --git a/app/models/badge.rb b/app/models/badge.rb index 2d2475b66df..5c398ff5ff3 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -36,7 +36,7 @@ class Badge < ActiveRecord::Base module Queries Reader = < #{Badge::AutobiographerMinBioLength} AND @@ -166,7 +166,7 @@ SQL def self.trust_level(level) # we can do better with dates, but its hard work figuring this out historically " - SELECT u.id user_id, current_timestamp granted_at, NULL post_id FROM users u + SELECT u.id user_id, current_timestamp granted_at FROM users u WHERE trust_level >= #{level.to_i} AND ( :backfill OR u.id IN (:user_ids) ) diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index 252e4501f03..ade8d503fa7 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -214,8 +214,21 @@ class BadgeGranter builder = SqlBuilder.new(sql) builder.where("ub.badge_id IS NULL AND q.user_id <> -1") - builder.where("q.post_id in (:post_ids)") if post_ids - builder.where("q.user_id in (:user_ids)") if user_ids + + if (post_ids || user_ids) && !badge.query.include?(":backfill") + Rails.logger.warn "Your triggered badge query for #{badge.name} does not include the :backfill param, skipping!" + return + end + + if (post_ids && !badge.query.include?(":post_ids")) + Rails.logger.warn "Your triggered badge query for #{badge.name} does not include the :post_ids param, skipping!" + return + end + + if (user_ids && !badge.query.include?(":user_ids")) + Rails.logger.warn "Your triggered badge query for #{badge.name} does not include the :user_ids param, skipping!" + return + end builder.map_exec(OpenStruct, id: badge.id, multiple_grant: badge.multiple_grant,