From 75e9a12493fc718e304047e37cfdfc437ecb89d2 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 9 May 2020 12:07:18 +0200 Subject: [PATCH] Add indexes to some heavily used tables haha queries go brrr --- db/migrate/20200509094402_add_some_indexes.rb | 13 +++++++++++++ db/schema.rb | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200509094402_add_some_indexes.rb diff --git a/db/migrate/20200509094402_add_some_indexes.rb b/db/migrate/20200509094402_add_some_indexes.rb new file mode 100644 index 00000000..e311a32b --- /dev/null +++ b/db/migrate/20200509094402_add_some_indexes.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddSomeIndexes < ActiveRecord::Migration[5.2] + def change + add_index :answers, :question_id + add_index :comments, :answer_id + add_index :inboxes, :user_id + add_index :reports, %i[type target_id] + add_index :reports, %i[user_id created_at] + add_index :services, :user_id + add_index :subscriptions, %i[user_id answer_id] + end +end diff --git a/db/schema.rb b/db/schema.rb index 0c1e34b5..499d010e 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: 2020_05_04_214933) do +ActiveRecord::Schema.define(version: 2020_05_09_094402) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -35,6 +35,7 @@ ActiveRecord::Schema.define(version: 2020_05_04_214933) do t.datetime "created_at" t.datetime "updated_at" t.integer "smile_count", default: 0, null: false + t.index ["question_id"], name: "index_answers_on_question_id" t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at" end @@ -55,6 +56,7 @@ ActiveRecord::Schema.define(version: 2020_05_04_214933) do t.datetime "created_at" t.datetime "updated_at" t.integer "smile_count", default: 0, null: false + t.index ["answer_id"], name: "index_comments_on_answer_id" t.index ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at" end @@ -86,6 +88,7 @@ ActiveRecord::Schema.define(version: 2020_05_04_214933) do t.boolean "new" t.datetime "created_at" t.datetime "updated_at" + t.index ["user_id"], name: "index_inboxes_on_user_id" end create_table "moderation_comments", id: :serial, force: :cascade do |t| @@ -147,6 +150,8 @@ ActiveRecord::Schema.define(version: 2020_05_04_214933) do t.datetime "updated_at" t.boolean "deleted", default: false t.string "reason" + t.index ["type", "target_id"], name: "index_reports_on_type_and_target_id" + t.index ["user_id", "created_at"], name: "index_reports_on_user_id_and_created_at" end create_table "roles", force: :cascade do |t| @@ -168,6 +173,7 @@ ActiveRecord::Schema.define(version: 2020_05_04_214933) do t.string "nickname" t.datetime "created_at" t.datetime "updated_at" + t.index ["user_id"], name: "index_services_on_user_id" end create_table "smiles", id: :serial, force: :cascade do |t| @@ -186,6 +192,7 @@ ActiveRecord::Schema.define(version: 2020_05_04_214933) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "is_active", default: true + t.index ["user_id", "answer_id"], name: "index_subscriptions_on_user_id_and_answer_id" end create_table "themes", id: :serial, force: :cascade do |t|