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?
This commit is contained in:
Emi Matchu 2024-10-02 17:55:20 -07:00
parent b6bddb14be
commit 03e4233f67
2 changed files with 6 additions and 3 deletions

View file

@ -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?)

View file

@ -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