diff --git a/lib/badge_queries.rb b/lib/badge_queries.rb index c73c579d5ca..1be3b1a8085 100644 --- a/lib/badge_queries.rb +++ b/lib/badge_queries.rb @@ -160,11 +160,15 @@ module BadgeQueries FROM invites i JOIN invited_users iu ON iu.invite_id = i.id JOIN users u2 ON u2.id = iu.user_id - WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= #{trust_level.to_i} AND u2.silenced_till IS NULL + WHERE i.deleted_at IS NULL + AND i.invited_by_id <> u2.id + AND u2.active + AND u2.trust_level >= #{trust_level.to_i} + AND u2.silenced_till IS NULL GROUP BY invited_by_id HAVING COUNT(*) >= #{count.to_i} ) AND u.active AND u.silenced_till IS NULL AND u.id > 0 AND - (:backfill OR u.id IN (:user_ids) ) + (:backfill OR u.id IN (:user_ids) ) SQL end