From 7b26f5086bfb072b9b1ba9a281d1a7b661d045c9 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Jul 2018 15:10:19 +1000 Subject: [PATCH] PERF: we have no use for topic percent rank Prepare to remove this column --- app/models/topic.rb | 4 +++- lib/score_calculator.rb | 18 ------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index c03848c5ed8..f7d973bbd24 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -31,6 +31,9 @@ class Topic < ActiveRecord::Base def_delegator :notifier, :mute!, :notify_muted! def_delegator :notifier, :toggle_mute, :toggle_mute + # TODO remove 01-01-2019 + self.ignored_columns = ["percent_rank"] + attr_accessor :allowed_user_ids, :tags_changed, :includes_destination_category DiscourseEvent.on(:site_setting_saved) do |site_setting| @@ -1433,7 +1436,6 @@ end # spam_count :integer default(0), not null # pinned_at :datetime # score :float -# percent_rank :float default(1.0), not null # subtype :string # slug :string # deleted_by_id :integer diff --git a/lib/score_calculator.rb b/lib/score_calculator.rb index 41272243ddd..69c8173d9b4 100644 --- a/lib/score_calculator.rb +++ b/lib/score_calculator.rb @@ -20,7 +20,6 @@ class ScoreCalculator update_posts_score(opts) update_posts_rank(opts) update_topics_rank(opts) - update_topics_percent_rank(opts) end private @@ -120,23 +119,6 @@ SQL builder.exec end - def update_topics_percent_rank(opts) - - builder = DB.build <<~SQL - UPDATE topics SET percent_rank = x.percent_rank - FROM (SELECT id, percent_rank() - OVER (ORDER BY SCORE DESC) as percent_rank - FROM topics) AS x - /*where*/ - SQL - - builder.where("x.id = topics.id AND (topics.percent_rank <> x.percent_rank OR topics.percent_rank IS NULL)") - - filter_topics(builder, opts) - - builder.exec - end - def filter_topics(builder, opts) return builder unless opts