Cache photos

This commit is contained in:
Brenda Wallace
2019-12-01 15:09:53 +13:00
committed by Brenda Wallace
parent 4065b1b248
commit d22fb68eee
2 changed files with 12 additions and 8 deletions

View File

@@ -1,14 +1,16 @@
module PhotosHelper
def crop_image_path(crop)
if crop.default_photo.present?
# The flickr thumbnails are too small, use full size
if crop.default_photo.source == 'flickr'
crop.default_photo.fullsize_url
Rails.cache.fetch("crop_image_path/#{crop.id}") do
if crop.default_photo.present?
# The flickr thumbnails are too small, use full size
if crop.default_photo.source == 'flickr'
crop.default_photo.fullsize_url
else
crop.default_photo.thumbnail_url
end
else
crop.default_photo.thumbnail_url
placeholder_image
end
else
placeholder_image
end
end

View File

@@ -12,7 +12,9 @@ module PhotoCapable
end
def most_liked_photo
photos.order(likes_count: :desc, created_at: :desc).first
Rails.cache.fetch("most_liked_photo/#{model_name}/#{id}") do
photos.order(likes_count: :desc, created_at: :desc).first
end
end
end
end