mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-11 00:02:05 -05:00
e1f293ad66
Removed sidetiq, introduced new scheduler - add basic UI - add schedule discover - add scheduling in initializer
30 lines
908 B
Ruby
30 lines
908 B
Ruby
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
|
|
|
|
end
|