mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-13 10:45:58 -04:00
Merge pull request #2327 from Br3nda/caching
Cache some heavy queries on models
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user