forked from OpenNeo/impress
Migrate item search away from item translations
Lightning fast for simple name queries now, gotta say!!
This commit is contained in:
parent
04af1ee319
commit
3ac9e7ce69
3 changed files with 11 additions and 28 deletions
|
@ -11,8 +11,8 @@ class ItemsController < ApplicationController
|
|||
else
|
||||
per_page = 30
|
||||
end
|
||||
@items = @query.results.includes(:translations).
|
||||
paginate(page: params[:page], per_page: per_page)
|
||||
@items = @query.results.paginate(
|
||||
page: params[:page], per_page: per_page)
|
||||
assign_closeted!
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
@ -44,7 +44,7 @@ class ItemsController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html {
|
||||
@campaign = Fundraising::Campaign.current rescue nil
|
||||
@newest_items = Item.newest.includes(:translations).limit(18)
|
||||
@newest_items = Item.newest.limit(18)
|
||||
}
|
||||
format.js { render json: {error: '$q required'}}
|
||||
end
|
||||
|
@ -86,8 +86,7 @@ class ItemsController < ApplicationController
|
|||
raise ActiveRecord::RecordNotFound, 'Pet type not found'
|
||||
end
|
||||
|
||||
@items = @pet_type.needed_items.includes(:translations).
|
||||
alphabetize_by_translations
|
||||
@items = @pet_type.needed_items.order(:name)
|
||||
assign_closeted!
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -28,13 +28,6 @@ class Item < ApplicationRecord
|
|||
cattr_reader :per_page
|
||||
@@per_page = 30
|
||||
|
||||
scope :alphabetize_by_translations, ->(locale) {
|
||||
locale = locale or I18n.locale
|
||||
it = Item::Translation.arel_table
|
||||
joins(:translations).where(it[:locale].eq('en')).
|
||||
order(it[:name].asc)
|
||||
}
|
||||
|
||||
scope :newest, -> {
|
||||
order(arel_table[:created_at].desc) if arel_table[:created_at]
|
||||
}
|
||||
|
@ -44,14 +37,10 @@ class Item < ApplicationRecord
|
|||
scope :with_closet_hangers, -> { joins(:closet_hangers) }
|
||||
|
||||
scope :name_includes, ->(value, locale = I18n.locale) {
|
||||
it = Item::Translation.arel_table
|
||||
Item.joins(:translations).where(it[:locale].eq(locale)).
|
||||
where(it[:name].matches('%' + sanitize_sql_like(value) + '%'))
|
||||
Item.where("name LIKE ?", "%" + sanitize_sql_like(value) + "%")
|
||||
}
|
||||
scope :name_excludes, ->(value, locale = I18n.locale) {
|
||||
it = Item::Translation.arel_table
|
||||
Item.joins(:translations).where(it[:locale].eq(locale)).
|
||||
where(it[:name].matches('%' + sanitize_sql_like(value) + '%').not)
|
||||
Item.where("name NOT LIKE ?", "%" + sanitize_sql_like(value) + "%")
|
||||
}
|
||||
scope :is_nc, -> {
|
||||
i = Item.arel_table
|
||||
|
@ -62,14 +51,10 @@ class Item < ApplicationRecord
|
|||
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc].eq(true)).not)
|
||||
}
|
||||
scope :is_pb, -> {
|
||||
it = Item::Translation.arel_table
|
||||
joins(:translations).where(it[:locale].eq('en')).
|
||||
where('description LIKE ?',
|
||||
'%' + sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||
}
|
||||
scope :is_not_pb, -> {
|
||||
it = Item::Translation.arel_table
|
||||
joins(:translations).where(it[:locale].eq('en')).
|
||||
where('description NOT LIKE ?',
|
||||
'%' + sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@ class Item
|
|||
end
|
||||
|
||||
def results
|
||||
@filters.map(&:to_query).inject(Item.all, &:merge).
|
||||
alphabetize_by_translations(Query.locale)
|
||||
@filters.map(&:to_query).inject(Item.all, &:merge).order(:name)
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
Loading…
Reference in a new issue