From 2bca1027a2bd335d8198d01f5814a0baba2d43a8 Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Tue, 23 May 2017 10:16:30 +0200 Subject: [PATCH] index all the things --- app/models/stories_paginator.rb | 3 ++- db/migrate/20170413161450_add_indexes.rb | 7 +++++++ db/schema.rb | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20170413161450_add_indexes.rb diff --git a/app/models/stories_paginator.rb b/app/models/stories_paginator.rb index 5aba99f..7afcf03 100644 --- a/app/models/stories_paginator.rb +++ b/app/models/stories_paginator.rb @@ -13,7 +13,8 @@ class StoriesPaginator def get with_pagination_info @scope.limit(per_page + 1) .offset((@page - 1) * per_page) - .includes(:user, :taggings => :tag) + .includes(:user, :suggested_titles, :suggested_taggings, + :taggings => :tag) end private diff --git a/db/migrate/20170413161450_add_indexes.rb b/db/migrate/20170413161450_add_indexes.rb new file mode 100644 index 0000000..85b2a69 --- /dev/null +++ b/db/migrate/20170413161450_add_indexes.rb @@ -0,0 +1,7 @@ +class AddIndexes < ActiveRecord::Migration + def change + add_index :votes, [ :comment_id ] + add_index :comments, [ :user_id ] + add_index :stories, [ :created_at ] + end +end diff --git a/db/schema.rb b/db/schema.rb index 4c45c69..6ed255c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170225201811) do +ActiveRecord::Schema.define(version: 20170413161450) do create_table "comments", force: :cascade do |t| t.datetime "created_at", null: false @@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20170225201811) do add_index "comments", ["short_id"], name: "short_id", unique: true, using: :btree add_index "comments", ["story_id", "short_id"], name: "story_id_short_id", using: :btree add_index "comments", ["thread_id"], name: "thread_id", using: :btree + add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree create_table "hat_requests", force: :cascade do |t| t.datetime "created_at" @@ -100,7 +101,6 @@ ActiveRecord::Schema.define(version: 20170225201811) do t.string "short_id", limit: 30 t.boolean "deleted_by_author", default: false t.boolean "deleted_by_recipient", default: false - t.integer "hat_id", limit: 4 end add_index "messages", ["short_id"], name: "random_hash", unique: true, using: :btree @@ -138,8 +138,11 @@ ActiveRecord::Schema.define(version: 20170225201811) do t.boolean "user_is_author", default: false end + add_index "stories", ["created_at"], name: "index_stories_on_created_at", using: :btree add_index "stories", ["hotness"], name: "hotness_idx", using: :btree add_index "stories", ["is_expired", "is_moderated"], name: "is_idxes", using: :btree + add_index "stories", ["is_expired"], name: "index_stories_on_is_expired", using: :btree + add_index "stories", ["is_moderated"], name: "index_stories_on_is_moderated", using: :btree add_index "stories", ["merged_story_id"], name: "index_stories_on_merged_story_id", using: :btree add_index "stories", ["short_id"], name: "unique_short_id", unique: true, using: :btree add_index "stories", ["twitter_id"], name: "index_stories_on_twitter_id", using: :btree @@ -225,6 +228,7 @@ ActiveRecord::Schema.define(version: 20170225201811) do t.string "reason", limit: 1 end + add_index "votes", ["comment_id"], name: "index_votes_on_comment_id", using: :btree add_index "votes", ["user_id", "comment_id"], name: "user_id_comment_id", using: :btree add_index "votes", ["user_id", "story_id"], name: "user_id_story_id", using: :btree