Add composite index to articles hotness_score and comments_count (#13724)

This commit is contained in:
rhymes 2021-05-11 18:39:56 +02:00 committed by GitHub
parent 423b2e8779
commit 860895a7cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1,15 @@
class AddIndexOnArticlesHotnessScoreCommentsCount < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
columns = %i[hotness_score comments_count]
add_index :articles, columns, algorithm: :concurrently unless index_exists?(:articles, columns)
end
def down
columns = %i[hotness_score comments_count]
remove_index :articles, column: columns, algorithm: :concurrently if index_exists?(:articles, columns)
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: 2021_04_30_094954) do
ActiveRecord::Schema.define(version: 2021_05_11_073505) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
@ -161,6 +161,7 @@ ActiveRecord::Schema.define(version: 2021_04_30_094954) do
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", "comments_count"], name: "index_articles_on_hotness_score_and_comments_count"
t.index ["hotness_score"], name: "index_articles_on_hotness_score"
t.index ["path"], name: "index_articles_on_path"
t.index ["public_reactions_count"], name: "index_articles_on_public_reactions_count", order: :desc