[deploy] Optimization: Add Index to Article Public Reaction Counts for Sorting (#8716)

This commit is contained in:
Molly Struve 2020-06-16 17:00:25 -05:00 committed by GitHub
parent 5ee80d2b1b
commit 76a0a96495
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 AddIndexToArticlesPublicReactionsCounts < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
if !index_exists?(:articles, :public_reactions_count)
add_index :articles, :public_reactions_count, order: { public_reactions_count: :desc }, algorithm: :concurrently
end
end
def down
if index_exists?(:articles, :public_reactions_count)
remove_index :articles, column: :public_reactions_count, algorithm: :concurrently
end
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: 2020_06_15_213003) do
ActiveRecord::Schema.define(version: 2020_06_16_200005) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -128,6 +128,7 @@ ActiveRecord::Schema.define(version: 2020_06_15_213003) do
t.index ["feed_source_url"], name: "index_articles_on_feed_source_url"
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
t.index ["published"], name: "index_articles_on_published"
t.index ["published_at"], name: "index_articles_on_published_at"
t.index ["slug"], name: "index_articles_on_slug"