2014-05-26 17:46:43 +08:00
|
|
|
module Jobs
|
|
|
|
class CreateMissingAvatars < Jobs::Scheduled
|
|
|
|
every 1.hour
|
|
|
|
def execute(args)
|
2014-05-28 09:50:49 +08:00
|
|
|
UserAvatar
|
|
|
|
.where("system_upload_id IS NULL OR system_avatar_version != ?", UserAvatar::SYSTEM_AVATAR_VERSION)
|
|
|
|
.find_each do |a|
|
2014-05-26 17:46:43 +08:00
|
|
|
a.update_system_avatar!
|
|
|
|
end
|
2014-05-27 18:46:17 +08:00
|
|
|
|
2014-05-28 09:50:49 +08:00
|
|
|
# backfill in batches 5000 an hour
|
2014-05-27 18:46:17 +08:00
|
|
|
User.where(uploaded_avatar_id: nil)
|
|
|
|
.order("last_posted_at desc")
|
2014-05-28 09:50:49 +08:00
|
|
|
.limit(5000).each do |u|
|
2014-05-27 18:46:17 +08:00
|
|
|
u.refresh_avatar
|
|
|
|
u.save
|
|
|
|
end
|
2014-05-26 17:46:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|