From 5a1034cab6ada90e76c1decf8e9ca847e2bf2c68 Mon Sep 17 00:00:00 2001 From: rhymes Date: Fri, 30 Apr 2021 15:02:27 +0200 Subject: [PATCH] [Search 2.0] Add index on articles.comments_count (#13599) --- ...094954_add_index_on_articles_comments_count.rb | 15 +++++++++++++++ db/schema.rb | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210430094954_add_index_on_articles_comments_count.rb diff --git a/db/migrate/20210430094954_add_index_on_articles_comments_count.rb b/db/migrate/20210430094954_add_index_on_articles_comments_count.rb new file mode 100644 index 000000000..684a0528c --- /dev/null +++ b/db/migrate/20210430094954_add_index_on_articles_comments_count.rb @@ -0,0 +1,15 @@ +class AddIndexOnArticlesCommentsCount < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def up + return if index_exists?(:articles, :comments_count) + + add_index :articles, :comments_count, algorithm: :concurrently + end + + def down + return unless index_exists?(:articles, :comments_count) + + remove_index :articles, column: :comments_count, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 30fe57b66..da6d2da3a 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: 2021_04_29_094116) do +ActiveRecord::Schema.define(version: 2021_04_30_094954) do # These are extensions that must be enabled in order to support this database enable_extension "citext" @@ -158,6 +158,7 @@ ActiveRecord::Schema.define(version: 2021_04_29_094116) do t.index ["canonical_url"], name: "index_articles_on_canonical_url", unique: true t.index ["collection_id"], name: "index_articles_on_collection_id" t.index ["comment_score"], name: "index_articles_on_comment_score" + t.index ["comments_count"], name: "index_articles_on_comments_count" t.index ["featured_number"], name: "index_articles_on_featured_number" t.index ["feed_source_url"], name: "index_articles_on_feed_source_url", unique: true t.index ["hotness_score"], name: "index_articles_on_hotness_score"