<commit_before>require_dependency 'avatar_detector'

module Jobs

  class DetectAvatars < Jobs::Scheduled
    every 8.hours

    def execute(args)
      return unless SiteSetting.detect_custom_avatars?

      # Find a random sampling of users of trust level 1 or higher who don't have a custom avatar.
      user_stats = UserStat.where('user_stats.has_custom_avatar = false AND users.trust_level > 0')
                           .includes(:user)
                           .order("random()")
                           .limit(SiteSetting.max_daily_gravatar_crawls)

      if user_stats.present?
        user_stats.each do |us|
          us.update_column(:has_custom_avatar, true) if AvatarDetector.new(us.user).has_custom_avatar?
          UserHistory.create!(
            action: UserHistory.actions[:checked_for_custom_avatar],
            target_user_id: us.user_id
          )
        end
      end
    end

  end<commit_msg>BUGFIX: failing avatar detection job<commit_after>require_dependency 'avatar_detector'

module Jobs

  class DetectAvatars < Jobs::Scheduled
    every 8.hours

    def execute(args)
      return unless SiteSetting.detect_custom_avatars?

      # Find a random sampling of users of trust level 1 or higher who don't have a custom avatar.
      user_stats = UserStat.where('user_stats.has_custom_avatar = false AND users.trust_level > 0')
                           .references(:user)
                           .includes(:user)
                           .order("random()")
                           .limit(SiteSetting.max_daily_gravatar_crawls)

      if user_stats.present?
        user_stats.each do |us|
          us.update_column(:has_custom_avatar, true) if AvatarDetector.new(us.user).has_custom_avatar?
          UserHistory.create!(
            action: UserHistory.actions[:checked_for_custom_avatar],
            target_user_id: us.user_id
          )
        end
      end
    end

  end
{'fraction_non_alphanumeric': 0.0742086144265698, 'fraction_numerical': 0.0031136481577581734, 'mean_word_length': 2.1815181518151814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2120350', 'n_tokens_mistral': 575, 'n_tokens_neox': 540, 'n_words': 122}