Remove "<New?>" from pet style search filters
When there's an unlabeled style, previously we'd include the placeholder value "<New?>" in the search dropdown, even though we don't actually support searching by it. Now, we don't! I did this in part by just refactoring how we look this stuff up, with queries that don't load *all* alt styles into memory, which will help perf a bit as more of them are released.
This commit is contained in:
parent
b8772c3aad
commit
fe6d42ef67
2 changed files with 16 additions and 9 deletions
|
@ -2,20 +2,15 @@ class AltStylesController < ApplicationController
|
|||
before_action :support_staff_only, except: [:index]
|
||||
|
||||
def index
|
||||
@all_alt_styles = AltStyle.includes(:species, :color)
|
||||
|
||||
@all_colors = @all_alt_styles.map(&:color).uniq.sort_by(&:name)
|
||||
@all_species = @all_alt_styles.map(&:species).uniq.sort_by(&:name)
|
||||
|
||||
@all_series_names = @all_alt_styles.map(&:series_name).uniq.sort
|
||||
@all_color_names = @all_colors.map(&:human_name)
|
||||
@all_species_names = @all_species.map(&:human_name)
|
||||
@all_series_names = AltStyle.all_series_names
|
||||
@all_color_names = AltStyle.all_supported_colors.map(&:human_name).sort
|
||||
@all_species_names = AltStyle.all_supported_species.map(&:human_name).sort
|
||||
|
||||
@series_name = params[:series]
|
||||
@color = find_color
|
||||
@species = find_species
|
||||
|
||||
@alt_styles = @all_alt_styles.includes(:swf_assets)
|
||||
@alt_styles = AltStyle.includes(:color, :species, :swf_assets)
|
||||
@alt_styles.where!(series_name: @series_name) if @series_name.present?
|
||||
@alt_styles.merge!(@color.alt_styles) if @color
|
||||
@alt_styles.merge!(@species.alt_styles) if @species
|
||||
|
|
|
@ -101,6 +101,18 @@ class AltStyle < ApplicationRecord
|
|||
"<New?>"
|
||||
end
|
||||
|
||||
def self.all_series_names
|
||||
distinct.where.not(series_name: nil).pluck(:series_name).sort
|
||||
end
|
||||
|
||||
def self.all_supported_colors
|
||||
Color.find(distinct.pluck(:color_id))
|
||||
end
|
||||
|
||||
def self.all_supported_species
|
||||
Species.find(distinct.pluck(:species_id))
|
||||
end
|
||||
|
||||
# For convenience in the console!
|
||||
def self.find_by_name(color_name, species_name)
|
||||
color = Color.find_by_name(color_name)
|
||||
|
|
Loading…
Reference in a new issue