From b9142161eb7b69efeee063dbdbdd227b72d612a4 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 10 Sep 2018 03:48:21 -0500 Subject: [PATCH] add additional indices --- app/views/content/form/_text_input.html.erb | 2 +- app/views/content/show.html.erb | 2 +- db/migrate/20180910084049_add_more_attribute_indices.rb | 6 ++++++ db/schema.rb | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180910084049_add_more_attribute_indices.rb diff --git a/app/views/content/form/_text_input.html.erb b/app/views/content/form/_text_input.html.erb index 8e9e5afa..dc25f524 100644 --- a/app/views/content/form/_text_input.html.erb +++ b/app/views/content/form/_text_input.html.erb @@ -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 %> diff --git a/app/views/content/show.html.erb b/app/views/content/show.html.erb index 2d40c3e9..a119422e 100644 --- a/app/views/content/show.html.erb +++ b/app/views/content/show.html.erb @@ -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 diff --git a/db/migrate/20180910084049_add_more_attribute_indices.rb b/db/migrate/20180910084049_add_more_attribute_indices.rb new file mode 100644 index 00000000..c938b566 --- /dev/null +++ b/db/migrate/20180910084049_add_more_attribute_indices.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5f3b867f..6d9215b6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"