add additional indices

This commit is contained in:
Andrew Brown 2018-09-10 03:48:21 -05:00
parent 95659b6220
commit b9142161eb
4 changed files with 11 additions and 3 deletions

View File

@ -6,7 +6,7 @@
if f.object.respond_to?(field.name.to_sym)
value = f.object.send(field.name.to_sym)
else
value = field.attribute_values.find_by(user: f.object.user, entity: f.object)
value = field.attribute_values.find_by(user: f.object.user, entity_type: f.object.class.name, entity_id: f.object.id)
end
%>

View File

@ -70,7 +70,7 @@
when 'universe'
Universe.find_by(id: content.universe_field_value)
when 'link', 'name', 'text_area', 'textearea' # todo update all textearea --> text_area in prod data
existing_attribute = attribute.attribute_values.find_by(entity_id: content.id)
existing_attribute = attribute.attribute_values.find_by(entity_id: content.id, entity_type: content.class.name)
if existing_attribute
existing_attribute.value

View File

@ -0,0 +1,6 @@
class AddMoreAttributeIndices < ActiveRecord::Migration[5.2]
def change
add_index(:attributes, [:deleted_at, :attribute_field_id, :entity_type, :entity_id], name: 'deleted_at__attribute_field_id__entity_type_and_id')
add_index(:attribute_fields, [:deleted_at, :attribute_category_id], name: 'deleted_at__attribute_category_id')
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_08_25_000628) do
ActiveRecord::Schema.define(version: 2018_09_10_084049) do
create_table "archenemyships", force: :cascade do |t|
t.integer "user_id"
@ -55,6 +55,7 @@ ActiveRecord::Schema.define(version: 2018_08_25_000628) do
t.boolean "hidden"
t.datetime "deleted_at"
t.string "old_column_source"
t.index ["deleted_at", "attribute_category_id"], name: "deleted_at__attribute_category_id"
t.index ["user_id", "attribute_category_id"], name: "index_attribute_fields_on_user_id_and_attribute_category_id"
t.index ["user_id", "field_type"], name: "index_attribute_fields_on_user_id_and_field_type"
t.index ["user_id", "name"], name: "index_attribute_fields_on_user_id_and_name"
@ -72,6 +73,7 @@ ActiveRecord::Schema.define(version: 2018_08_25_000628) do
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "deleted_at"
t.index ["deleted_at", "attribute_field_id", "entity_type", "entity_id"], name: "deleted_at__attribute_field_id__entity_type_and_id"
t.index ["entity_type", "entity_id"], name: "index_attributes_on_entity_type_and_entity_id"
t.index ["user_id", "attribute_field_id"], name: "index_attributes_on_user_id_and_attribute_field_id"
t.index ["user_id", "entity_type", "entity_id"], name: "index_attributes_on_user_id_and_entity_type_and_entity_id"