Skip to content

A platform for community discussion. Free, open, simple.

PERF: Drop unused indexes on top_topics table (#37053)

Alan Guo Xiang Tan24d4fc48253d
diff --git a/app/models/top_topic.rb b/app/models/top_topic.rb
index 93da90bf32b..04664f6df2c 100644
--- a/app/models/top_topic.rb
+++ b/app/models/top_topic.rb
@@ -250,60 +250,40 @@ end
# Table name: top_topics
#
# id :integer not null, primary key
-# topic_id :integer
-# yearly_posts_count :integer default(0), not null
-# yearly_views_count :integer default(0), not null
-# yearly_likes_count :integer default(0), not null
-# monthly_posts_count :integer default(0), not null
-# monthly_views_count :integer default(0), not null
-# monthly_likes_count :integer default(0), not null
-# weekly_posts_count :integer default(0), not null
-# weekly_views_count :integer default(0), not null
-# weekly_likes_count :integer default(0), not null
-# daily_posts_count :integer default(0), not null
-# daily_views_count :integer default(0), not null
-# daily_likes_count :integer default(0), not null
-# daily_score :float default(0.0)
-# weekly_score :float default(0.0)
-# monthly_score :float default(0.0)
-# yearly_score :float default(0.0)
# all_score :float default(0.0)
+# daily_likes_count :integer default(0), not null
# daily_op_likes_count :integer default(0), not null
-# weekly_op_likes_count :integer default(0), not null
+# daily_posts_count :integer default(0), not null
+# daily_score :float default(0.0)
+# daily_views_count :integer default(0), not null
+# monthly_likes_count :integer default(0), not null
# monthly_op_likes_count :integer default(0), not null
-# yearly_op_likes_count :integer default(0), not null
-# quarterly_posts_count :integer default(0), not null
-# quarterly_views_count :integer default(0), not null
+# monthly_posts_count :integer default(0), not null
+# monthly_score :float default(0.0)
+# monthly_views_count :integer default(0), not null
# quarterly_likes_count :integer default(0), not null
-# quarterly_score :float default(0.0)
# quarterly_op_likes_count :integer default(0), not null
+# quarterly_posts_count :integer default(0), not null
+# quarterly_score :float default(0.0)
+# quarterly_views_count :integer default(0), not null
+# weekly_likes_count :integer default(0), not null
+# weekly_op_likes_count :integer default(0), not null
+# weekly_posts_count :integer default(0), not null
+# weekly_score :float default(0.0)
+# weekly_views_count :integer default(0), not null
+# yearly_likes_count :integer default(0), not null
+# yearly_op_likes_count :integer default(0), not null
+# yearly_posts_count :integer default(0), not null
+# yearly_score :float default(0.0)
+# yearly_views_count :integer default(0), not null
+# topic_id :integer
#
# Indexes
#
-# index_top_topics_on_all_score (all_score)
-# index_top_topics_on_daily_likes_count (daily_likes_count)
-# index_top_topics_on_daily_op_likes_count (daily_op_likes_count)
-# index_top_topics_on_daily_posts_count (daily_posts_count)
-# index_top_topics_on_daily_score (daily_score)
-# index_top_topics_on_daily_views_count (daily_views_count)
-# index_top_topics_on_monthly_likes_count (monthly_likes_count)
-# index_top_topics_on_monthly_op_likes_count (monthly_op_likes_count)
-# index_top_topics_on_monthly_posts_count (monthly_posts_count)
-# index_top_topics_on_monthly_score (monthly_score)
-# index_top_topics_on_monthly_views_count (monthly_views_count)
-# index_top_topics_on_quarterly_likes_count (quarterly_likes_count)
-# index_top_topics_on_quarterly_op_likes_count (quarterly_op_likes_count)
-# index_top_topics_on_quarterly_posts_count (quarterly_posts_count)
-# index_top_topics_on_quarterly_views_count (quarterly_views_count)
-# index_top_topics_on_topic_id (topic_id) UNIQUE
-# index_top_topics_on_weekly_likes_count (weekly_likes_count)
-# index_top_topics_on_weekly_op_likes_count (weekly_op_likes_count)
-# index_top_topics_on_weekly_posts_count (weekly_posts_count)
-# index_top_topics_on_weekly_score (weekly_score)
-# index_top_topics_on_weekly_views_count (weekly_views_count)
-# index_top_topics_on_yearly_likes_count (yearly_likes_count)
-# index_top_topics_on_yearly_op_likes_count (yearly_op_likes_count)
-# index_top_topics_on_yearly_posts_count (yearly_posts_count)
-# index_top_topics_on_yearly_score (yearly_score)
-# index_top_topics_on_yearly_views_count (yearly_views_count)
+# index_top_topics_on_all_score (all_score)
+# index_top_topics_on_daily_score (daily_score)
+# index_top_topics_on_monthly_score (monthly_score)
+# index_top_topics_on_topic_id (topic_id) UNIQUE
+# index_top_topics_on_weekly_score (weekly_score)
+# index_top_topics_on_yearly_score (yearly_score)
#
diff --git a/db/migrate/20260112032646_drop_unused_top_topics_count_indexes.rb b/db/migrate/20260112032646_drop_unused_top_topics_count_indexes.rb
new file mode 100644
index 00000000000..d087e67b6be
--- /dev/null
+++ b/db/migrate/20260112032646_drop_unused_top_topics_count_indexes.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class DropUnusedTopTopicsCountIndexes < ActiveRecord::Migration[8.0]
+ def up
+ remove_index :top_topics, :daily_posts_count
+ remove_index :top_topics, :daily_views_count
+ remove_index :top_topics, :daily_likes_count
+ remove_index :top_topics, :daily_op_likes_count
+ remove_index :top_topics, :weekly_posts_count
+ remove_index :top_topics, :weekly_views_count
+ remove_index :top_topics, :weekly_likes_count
+ remove_index :top_topics, :weekly_op_likes_count
+ remove_index :top_topics, :monthly_posts_count
+ remove_index :top_topics, :monthly_views_count
+ remove_index :top_topics, :monthly_likes_count
+ remove_index :top_topics, :monthly_op_likes_count
+ remove_index :top_topics, :quarterly_posts_count
+ remove_index :top_topics, :quarterly_views_count
+ remove_index :top_topics, :quarterly_likes_count
+ remove_index :top_topics, :quarterly_op_likes_count
+ remove_index :top_topics, :yearly_posts_count
+ remove_index :top_topics, :yearly_views_count
+ remove_index :top_topics, :yearly_likes_count
+ remove_index :top_topics, :yearly_op_likes_count
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end