From 176ab20fd110db5d097123a5b834470f5b64c737 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 5 Sep 2024 17:41:04 -0700 Subject: [PATCH] Cache the `Item#appearances` field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We call it enough times on this page, and it *does* have a SQL query, that I want to cache it! (Also I want to make it fewer species queries if I can tbh…) --- app/models/item.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/item.rb b/app/models/item.rb index 100f4bc3..289251b5 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -533,6 +533,10 @@ class Item < ApplicationRecord end def appearances + @appearances ||= build_appearances + end + + def build_appearances all_swf_assets = swf_assets.to_a # If there are no assets yet, there are no appearances.