Compare commits

..

No commits in common. "193b1fa5e31118f8ed8f222ebbc5a632e06c41a7" and "63abfa51f7821b084ddde263e4bbc581a2f25646" have entirely different histories.

3 changed files with 2 additions and 23 deletions

View file

@ -60,23 +60,8 @@ class Item < ApplicationRecord
}
scope :occupies, ->(zone_label) {
zone_ids = Zone.matching_label(zone_label).map(&:id)
# NOTE: In searches, this query performs much better using a subquery
# instead of joins! This is because, in the joins case, filtering by an
# `swf_assets` field but sorting by an `items` field causes the query
# planner to only be able to use an index for *one* of them. In this case,
# MySQL can use the `swf_assets`.`zone_id` index to get the item IDs for
# the subquery, then use the `items`.`name` index to sort them.
i = arel_table
psa = ParentSwfAssetRelationship.arel_table
sa = SwfAsset.arel_table
where(
ParentSwfAssetRelationship.joins(:swf_asset).
where(sa[:zone_id].in(zone_ids)).
where(psa[:parent_type].eq("Item")).
where(psa[:parent_id].eq(i[:id])).
arel.exists
)
joins(:swf_assets).where(sa[:zone_id].in(zone_ids)).distinct
}
scope :not_occupies, ->(zone_label) {
zone_ids = Zone.matching_label(zone_label).map(&:id)

View file

@ -1,5 +0,0 @@
class AddIndexOnNameToItems < ActiveRecord::Migration[7.1]
def change
add_index :items, :name
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_06_03_181855) do
ActiveRecord::Schema[7.1].define(version: 2024_05_22_233638) do
create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.integer "species_id", null: false
t.integer "color_id", null: false
@ -140,7 +140,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_03_181855) do
t.index ["modeling_status_hint", "created_at"], name: "items_modeling_status_hint_and_created_at"
t.index ["modeling_status_hint", "id"], name: "items_modeling_status_hint_and_id"
t.index ["modeling_status_hint"], name: "items_modeling_status_hint"
t.index ["name"], name: "index_items_on_name"
end
create_table "login_cookies", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|