From 03e4233f67935b6e8998904d41305fb41f7660af Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Wed, 2 Oct 2024 17:55:20 -0700 Subject: [PATCH] Use cached compatible body IDs on homepage modeling code This should make it load way faster! Maybe don't even need to mess with caching the resulting HTML anymore, like we currently do? --- app/controllers/outfits_controller.rb | 3 ++- app/models/item.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/outfits_controller.rb b/app/controllers/outfits_controller.rb index 1e55eb47..80fb1cf5 100644 --- a/app/controllers/outfits_controller.rb +++ b/app/controllers/outfits_controller.rb @@ -52,7 +52,8 @@ class OutfitsController < ApplicationController # HACK: Skip this in development, because it's slow! newest_items = Item.newest. - select(:id, :name, :updated_at, :thumbnail_url, :rarity_index, :is_manually_nc) + select(:id, :name, :updated_at, :thumbnail_url, :rarity_index, + :is_manually_nc, :cached_compatible_body_ids) .limit(18) @newest_modeled_items, @newest_unmodeled_items = newest_items.partition(&:predicted_fully_modeled?) diff --git a/app/models/item.rb b/app/models/item.rb index 3e5fa04f..77e71910 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -262,7 +262,7 @@ class Item < ApplicationRecord def update_cached_fields self.cached_occupied_zone_ids = occupied_zone_ids - self.cached_compatible_body_ids = compatible_body_ids + self.cached_compatible_body_ids = compatible_body_ids(use_cached: false) self.save! end @@ -376,7 +376,9 @@ class Item < ApplicationRecord }.merge(options)) end - def compatible_body_ids + def compatible_body_ids(use_cached: true) + return cached_compatible_body_ids if use_cached + swf_assets.map(&:body_id).uniq end