Remove references to species/color translations at call sites

We wisely did preloading in some places. Now, we don't need to!
Hopefully this'll even be a free speed boost on some pages!
This commit is contained in:
Emi Matchu 2024-01-23 05:23:57 -08:00
parent 0dca538b0a
commit ce64f12cc3
7 changed files with 11 additions and 21 deletions

View file

@ -11,8 +11,7 @@ class ContributionsController < ApplicationController
@contributions, @contributions,
:scopes => { :scopes => {
'Item' => Item.includes(:translations), 'Item' => Item.includes(:translations),
'PetType' => PetType.includes({:species => :translations, 'PetType' => PetType.includes(:species, :color)
:color => :translations})
} }
) )
end end

View file

@ -59,12 +59,9 @@ class OutfitsController < ApplicationController
@newest_unmodeled_items_predicted_missing_species_by_color = {} @newest_unmodeled_items_predicted_missing_species_by_color = {}
@newest_unmodeled_items_predicted_modeled_ratio = {} @newest_unmodeled_items_predicted_modeled_ratio = {}
@newest_unmodeled_items.each do |item| @newest_unmodeled_items.each do |item|
h = item.predicted_missing_nonstandard_body_ids_by_species_by_color( h = item.predicted_missing_nonstandard_body_ids_by_species_by_color
Color.includes(:translations),
Species.includes(:translations))
standard_body_ids_by_species = item. standard_body_ids_by_species = item.
predicted_missing_standard_body_ids_by_species( predicted_missing_standard_body_ids_by_species
Species.includes(:translations))
if standard_body_ids_by_species.present? if standard_body_ids_by_species.present?
h[:standard] = standard_body_ids_by_species h[:standard] = standard_body_ids_by_species
end end

View file

@ -2,7 +2,7 @@ class PetTypesController < ApplicationController
def index def index
color = Color.find params[:color_id] color = Color.find params[:color_id]
pet_types = color.pet_types.includes(pet_states: [:swf_assets]). pet_types = color.pet_types.includes(pet_states: [:swf_assets]).
includes(species: [:translations]) includes(:species)
# This is a relatively big request, for relatively static data. Let's # This is a relatively big request, for relatively static data. Let's
# consider it fresh for 10min (so new pet releases show up quickly), but # consider it fresh for 10min (so new pet releases show up quickly), but

View file

@ -106,7 +106,7 @@ module ItemsHelper
species_ids = species.map(&:id) species_ids = species.map(&:id)
pet_types = special_color ? pet_types = special_color ?
PetType.where(:color_id => special_color.id, :species_id => species_ids). PetType.where(:color_id => special_color.id, :species_id => species_ids).
order(:species_id).includes_child_translations : order(:species_id) :
PetType.random_basic_per_species(species.map(&:id)) PetType.random_basic_per_species(species.map(&:id))
pet_types.map(&block).join.html_safe pet_types.map(&block).join.html_safe
end end

View file

@ -352,8 +352,8 @@ class Item < ApplicationRecord
inject({}) { |h, pt| h[pt.species_id] = pt.body_id; h } inject({}) { |h, pt| h[pt.species_id] = pt.body_id; h }
end end
def predicted_missing_standard_body_ids_by_species(species_scope=Species.all) def predicted_missing_standard_body_ids_by_species
species = species_scope.where(id: predicted_missing_standard_body_ids_by_species_id.keys) species = Species.where(id: predicted_missing_standard_body_ids_by_species_id.keys)
species_by_id = species.inject({}) { |h, s| h[s.id] = s; h } species_by_id = species.inject({}) { |h, s| h[s.id] = s; h }
predicted_missing_standard_body_ids_by_species_id.inject({}) { |h, (sid, bid)| predicted_missing_standard_body_ids_by_species_id.inject({}) { |h, (sid, bid)|
h[species_by_id[sid]] = bid; h } h[species_by_id[sid]] = bid; h }
@ -365,16 +365,16 @@ class Item < ApplicationRecord
colors: {standard: false}) colors: {standard: false})
end end
def predicted_missing_nonstandard_body_ids_by_species_by_color(colors_scope=Color.all, species_scope=Species.all) def predicted_missing_nonstandard_body_ids_by_species_by_color
pet_types = predicted_missing_nonstandard_body_pet_types pet_types = predicted_missing_nonstandard_body_pet_types
species_by_id = {} species_by_id = {}
species_scope.find(pet_types.map(&:species_id)).each do |species| Species.find(pet_types.map(&:species_id)).each do |species|
species_by_id[species.id] = species species_by_id[species.id] = species
end end
colors_by_id = {} colors_by_id = {}
colors_scope.find(pet_types.map(&:color_id)).each do |color| Color.find(pet_types.map(&:color_id)).each do |color|
colors_by_id[color.id] = color colors_by_id[color.id] = color
end end

View file

@ -19,9 +19,6 @@ class PetType < ApplicationRecord
scope :nonstandard_colors, -> { where(:color_id => Color.nonstandard) } scope :nonstandard_colors, -> { where(:color_id => Color.nonstandard) }
scope :includes_child_translations,
-> { includes({:color => :translations, :species => :translations}) }
scope :matching_name, ->(color_name, species_name) { scope :matching_name, ->(color_name, species_name) {
color = Color.find_by_name!(color_name) color = Color.find_by_name!(color_name)
species = Species.find_by_name!(species_name) species = Species.find_by_name!(species_name)

View file

@ -2,10 +2,7 @@ class Species < ApplicationRecord
translates # TODO: Remove once we're all done with translations! translates # TODO: Remove once we're all done with translations!
has_many :pet_types has_many :pet_types
scope :alphabetical, -> { scope :alphabetical, -> { order(:name) }
st = Species::Translation.arel_table
with_translations(I18n.locale).order(st[:name].asc)
}
scope :with_body_id, -> body_id { scope :with_body_id, -> body_id {
pt = PetType.arel_table pt = PetType.arel_table