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:
parent
0dca538b0a
commit
ce64f12cc3
7 changed files with 11 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue