From 2e56f8cb2fd428fe8295c2b1f6b0c44c296fd5ee Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 27 Apr 2026 03:52:11 +0000 Subject: [PATCH] Cache what a crop is harvested for --- app/controllers/charts/crops_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/charts/crops_controller.rb b/app/controllers/charts/crops_controller.rb index a48ec1ab2..848c7161d 100644 --- a/app/controllers/charts/crops_controller.rb +++ b/app/controllers/charts/crops_controller.rb @@ -14,9 +14,12 @@ module Charts def harvested_for @crop = Crop.find_by!(slug: params[:crop_slug]) - render json: Harvest.joins(:plant_part) - .where(crop: @crop) - .group("plant_parts.name").count(:id) + data = Rails.cache.fetch("#{@crop.cache_key_with_version}/harvested_for", expires_in: 1.day) do + Harvest.joins(:plant_part) + .where(crop: @crop) + .group("plant_parts.name").count(:id) + end + render json: data end private