Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created February 24, 2011 20:21
Show Gist options
  • Save brandon-beacher/842813 to your computer and use it in GitHub Desktop.
Save brandon-beacher/842813 to your computer and use it in GitHub Desktop.
#
# https://www.pivotaltracker.com/projects/69655?story_id=10380873
#
# It appears some of the photos are missing styles.
# It could be the style was added to has_attached_file in MlsPhoto
# and the photos were never reprocessed at that time.
# This utility class will walk through the MlsPhotos
# and reprocess any who's styles are missing from disk.
#
class MlsPhotoReprocessor
extend ActionView::Helpers::NumberHelper
def self.reprocess!
count = MlsPhoto.count
index = 0
MlsPhoto.find_in_batches do |mls_photos|
puts "examining batch #{index} of #{count} (#{percentage(index, count)})"
index += mls_photos.length
mls_photos.each do |mls_photo|
photo = mls_photo.photo
photo.styles.keys.each do |style|
path = photo.path(style)
unless File.exists?(path)
puts "missing: #{path}"
photo.reprocess!
end
end
end
end
end
private
def self.percentage(index, count)
number_to_percentage((index.to_f / count.to_f) * 100, :precision => 0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment