Merge pull request #2327 from Br3nda/caching

Cache some heavy queries on models
This commit is contained in:
Brenda Wallace authored and GitHub committed 2019-12-14 14:18:24 +13:00
commit fc69507f37
2 files changed
+13 -9

No files matched your search

+3 -1
View File
@@ -8,7 +8,9 @@ module PhotoCapable
scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) }
def default_photo
most_liked_photo
Rails.cache.fetch("#{cache_key_with_version}/default_photo", expires_in: 8.hours) do
most_liked_photo
end
end
def most_liked_photo
+10 -8
View File
@@ -42,14 +42,16 @@ module PredictPlanting
end
def percentage_grown
if finished?
100
elsif !planted?
0
elsif crop.perennial || finish_predicted_at.nil?
nil
else
calculate_percentage_grown
Rails.cache.fetch("#{cache_key_with_version}/percentage_grown", expires_in: 8.hours) do
if finished?
100
elsif !planted?
0
elsif crop.perennial || finish_predicted_at.nil?
nil
else
calculate_percentage_grown
end
end
end