From ce64f12cc3646f17b1dc33bf9ef8de3dd5d1bdd2 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 23 Jan 2024 05:23:57 -0800 Subject: [PATCH] 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! --- app/controllers/contributions_controller.rb | 3 +-- app/controllers/outfits_controller.rb | 7 ++----- app/controllers/pet_types_controller.rb | 2 +- app/helpers/items_helper.rb | 2 +- app/models/item.rb | 10 +++++----- app/models/pet_type.rb | 3 --- app/models/species.rb | 5 +---- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/app/controllers/contributions_controller.rb b/app/controllers/contributions_controller.rb index 2d37be10..018c270c 100644 --- a/app/controllers/contributions_controller.rb +++ b/app/controllers/contributions_controller.rb @@ -11,8 +11,7 @@ class ContributionsController < ApplicationController @contributions, :scopes => { 'Item' => Item.includes(:translations), - 'PetType' => PetType.includes({:species => :translations, - :color => :translations}) + 'PetType' => PetType.includes(:species, :color) } ) end diff --git a/app/controllers/outfits_controller.rb b/app/controllers/outfits_controller.rb index ed3282ea..e8d41d6a 100644 --- a/app/controllers/outfits_controller.rb +++ b/app/controllers/outfits_controller.rb @@ -59,12 +59,9 @@ class OutfitsController < ApplicationController @newest_unmodeled_items_predicted_missing_species_by_color = {} @newest_unmodeled_items_predicted_modeled_ratio = {} @newest_unmodeled_items.each do |item| - h = item.predicted_missing_nonstandard_body_ids_by_species_by_color( - Color.includes(:translations), - Species.includes(:translations)) + h = item.predicted_missing_nonstandard_body_ids_by_species_by_color standard_body_ids_by_species = item. - predicted_missing_standard_body_ids_by_species( - Species.includes(:translations)) + predicted_missing_standard_body_ids_by_species if standard_body_ids_by_species.present? h[:standard] = standard_body_ids_by_species end diff --git a/app/controllers/pet_types_controller.rb b/app/controllers/pet_types_controller.rb index bcef99e7..3c5e9754 100644 --- a/app/controllers/pet_types_controller.rb +++ b/app/controllers/pet_types_controller.rb @@ -2,7 +2,7 @@ class PetTypesController < ApplicationController def index color = Color.find params[:color_id] 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 # consider it fresh for 10min (so new pet releases show up quickly), but diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index b0071929..ec998736 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -106,7 +106,7 @@ module ItemsHelper species_ids = species.map(&:id) pet_types = special_color ? 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)) pet_types.map(&block).join.html_safe end diff --git a/app/models/item.rb b/app/models/item.rb index 8b3a8ee5..26024396 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -352,8 +352,8 @@ class Item < ApplicationRecord inject({}) { |h, pt| h[pt.species_id] = pt.body_id; h } end - def predicted_missing_standard_body_ids_by_species(species_scope=Species.all) - species = species_scope.where(id: predicted_missing_standard_body_ids_by_species_id.keys) + def predicted_missing_standard_body_ids_by_species + 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 } predicted_missing_standard_body_ids_by_species_id.inject({}) { |h, (sid, bid)| h[species_by_id[sid]] = bid; h } @@ -365,16 +365,16 @@ class Item < ApplicationRecord colors: {standard: false}) 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 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 end 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 end diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 2ab62fc0..b0e6f5de 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -19,9 +19,6 @@ class PetType < ApplicationRecord scope :nonstandard_colors, -> { where(:color_id => Color.nonstandard) } - scope :includes_child_translations, - -> { includes({:color => :translations, :species => :translations}) } - scope :matching_name, ->(color_name, species_name) { color = Color.find_by_name!(color_name) species = Species.find_by_name!(species_name) diff --git a/app/models/species.rb b/app/models/species.rb index b38bd037..f6f08e18 100644 --- a/app/models/species.rb +++ b/app/models/species.rb @@ -2,10 +2,7 @@ class Species < ApplicationRecord translates # TODO: Remove once we're all done with translations! has_many :pet_types - scope :alphabetical, -> { - st = Species::Translation.arel_table - with_translations(I18n.locale).order(st[:name].asc) - } + scope :alphabetical, -> { order(:name) } scope :with_body_id, -> body_id { pt = PetType.arel_table