mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 23:40:09 +08:00
322a3be2db
Constants should always be only assigned once. The logical OR assignment of a constant is a relic of the past before we used zeitwerk for autoloading and had bugs where a file could be loaded twice resulting in constant redefinition warnings.
25 lines
634 B
Ruby
25 lines
634 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class UpdateAnimatedUploads < ::Jobs::Scheduled
|
|
every 1.hour
|
|
|
|
MAX_PROCESSED_GIF_IMAGES = 200
|
|
|
|
def execute(args)
|
|
Upload
|
|
.where("extension = 'gif' OR (extension IS NULL AND original_filename LIKE '%.gif')")
|
|
.where(animated: nil)
|
|
.limit(MAX_PROCESSED_GIF_IMAGES)
|
|
.each do |upload|
|
|
uri = Discourse.store.path_for(upload) || upload.url
|
|
upload.animated = FastImage.animated?(uri)
|
|
upload.save(validate: false)
|
|
upload.optimized_images.destroy_all if upload.animated
|
|
end
|
|
|
|
nil
|
|
end
|
|
end
|
|
end
|