From f0f1e878feb6fd2909242482161ea7f4918abc7c Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 20 Mar 2019 17:16:30 +0800 Subject: [PATCH] PERF: Add index to speed up `User#number_of_flagged_posts`. On meta, we were seeing the query take almost 100ms. --- ...ndex_post_action_type_id_disagreed_at_on_post_actions.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 db/migrate/20190320091323_add_index_post_action_type_id_disagreed_at_on_post_actions.rb diff --git a/db/migrate/20190320091323_add_index_post_action_type_id_disagreed_at_on_post_actions.rb b/db/migrate/20190320091323_add_index_post_action_type_id_disagreed_at_on_post_actions.rb new file mode 100644 index 00000000000..6b23f10974c --- /dev/null +++ b/db/migrate/20190320091323_add_index_post_action_type_id_disagreed_at_on_post_actions.rb @@ -0,0 +1,6 @@ +class AddIndexPostActionTypeIdDisagreedAtOnPostActions < ActiveRecord::Migration[5.2] + def change + add_index :post_actions, [:post_action_type_id, :disagreed_at], + where: "(disagreed_at IS NULL)" + end +end