From 6818ef3ed01b30e4f7651aa0595c8f89aa4055fe Mon Sep 17 00:00:00 2001 From: Monica Mateiu Date: Fri, 15 Apr 2022 16:43:48 +0100 Subject: [PATCH] Remove references to article.spaminess_rating (#17235) * Remove references to article.spaminess * Update app/models/article.rb * Update spec/workers/comments/calculate_score_worker_spec.rb Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> * remove unnecessary BlackBox spec * Update spec/workers/comments/calculate_score_worker_spec.rb Co-authored-by: Jamie Gaskins * Remove references to calculate_spaminess * Update app/workers/comments/calculate_score_worker.rb Co-authored-by: Jamie Gaskins Co-authored-by: Jeremy Friesen Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Co-authored-by: Jamie Gaskins Co-authored-by: Jamie Gaskins --- app/lib/black_box.rb | 10 ++-------- app/models/article.rb | 4 +--- app/services/articles/feeds/weighted_query_strategy.rb | 8 -------- app/workers/comments/calculate_score_worker.rb | 3 +-- spec/lib/black_box_spec.rb | 10 ---------- spec/workers/articles/score_calc_worker_spec.rb | 5 +---- spec/workers/comments/calculate_score_worker_spec.rb | 4 +--- 7 files changed, 6 insertions(+), 38 deletions(-) diff --git a/app/lib/black_box.rb b/app/lib/black_box.rb index fa36c90e6..d9cc50d38 100644 --- a/app/lib/black_box.rb +++ b/app/lib/black_box.rb @@ -32,12 +32,7 @@ class BlackBox descendants_points = (comment.descendants.size / 2) rep_points = comment.reactions.sum(:points) bonus_points = calculate_bonus_score(comment.body_markdown) - spaminess_rating = calculate_spaminess(comment) - (rep_points + descendants_points + bonus_points - spaminess_rating).to_i - end - - def calculate_spaminess(story) - story.user ? 0 : 100 + (rep_points + descendants_points + bonus_points).to_i end private @@ -52,8 +47,7 @@ class BlackBox score_from_epoch = article.featured_number.to_i - OUR_EPOCH_NUMBER # Approximate time of publish - epoch time (score_from_epoch / 1000) + ([article.score, 650].min * 2) + - ([article.comment_score, 650].min * 2) - - (article.spaminess_rating * 5) + ([article.comment_score, 650].min * 2) end end end diff --git a/app/models/article.rb b/app/models/article.rb index 7a30dbf4c..5e0627534 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -557,8 +557,7 @@ class Article < ApplicationRecord update_columns(score: score, privileged_users_reaction_points_sum: reactions.privileged_category.sum(:points), comment_score: comments.sum(:score), - hotness_score: BlackBox.article_hotness_score(self), - spaminess_rating: BlackBox.calculate_spaminess(self)) + hotness_score: BlackBox.article_hotness_score(self)) end def co_author_ids_list=(list_of_co_author_ids) @@ -903,7 +902,6 @@ class Article < ApplicationRecord def calculate_base_scores self.hotness_score = 1000 if hotness_score.blank? - self.spaminess_rating = 0 if new_record? end def create_conditional_autovomits diff --git a/app/services/articles/feeds/weighted_query_strategy.rb b/app/services/articles/feeds/weighted_query_strategy.rb index d9c373cbc..b08901608 100644 --- a/app/services/articles/feeds/weighted_query_strategy.rb +++ b/app/services/articles/feeds/weighted_query_strategy.rb @@ -227,14 +227,6 @@ module Articles fallback: 1, requires_user: false, group_by: "articles.public_reactions_count" - }, - # Weight to give based on spaminess of the article. - spaminess_factor: { - clause: "articles.spaminess_rating", - cases: [[0, 1]], - fallback: 0, - requires_user: false, - group_by: "articles.spaminess_rating" } }.freeze diff --git a/app/workers/comments/calculate_score_worker.rb b/app/workers/comments/calculate_score_worker.rb index 52344600b..40e2447b6 100644 --- a/app/workers/comments/calculate_score_worker.rb +++ b/app/workers/comments/calculate_score_worker.rb @@ -9,9 +9,8 @@ module Comments return unless comment score = BlackBox.comment_quality_score(comment) - spaminess_rating = BlackBox.calculate_spaminess(comment) - comment.update_columns(score: score, spaminess_rating: spaminess_rating) + comment.update_columns(score: score) comment.root.save! if !comment.is_root? && comment.root_exists? end end diff --git a/spec/lib/black_box_spec.rb b/spec/lib/black_box_spec.rb index 558dbece8..30fef0e67 100644 --- a/spec/lib/black_box_spec.rb +++ b/spec/lib/black_box_spec.rb @@ -28,14 +28,4 @@ RSpec.describe BlackBox, type: :lib do expect(described_class.comment_quality_score(comment)).to eq(25) end end - - describe "#calculate_spaminess" do - let(:user) { build_stubbed(:user) } - let(:comment) { build_stubbed(:comment, user: user) } - - it "returns 100 if there is no user" do - story = instance_double("Comment", user: nil) - expect(described_class.calculate_spaminess(story)).to eq(100) - end - end end diff --git a/spec/workers/articles/score_calc_worker_spec.rb b/spec/workers/articles/score_calc_worker_spec.rb index 7e72e1256..7ffc7c521 100644 --- a/spec/workers/articles/score_calc_worker_spec.rb +++ b/spec/workers/articles/score_calc_worker_spec.rb @@ -9,7 +9,6 @@ RSpec.describe Articles::ScoreCalcWorker, type: :worker do describe "#perform_now" do before do allow(BlackBox).to receive(:article_hotness_score).and_return(373) - allow(BlackBox).to receive(:calculate_spaminess).and_return(2) end context "with article" do @@ -29,7 +28,6 @@ RSpec.describe Articles::ScoreCalcWorker, type: :worker do expect(article.score).to be(7) expect(article.comment_score).to be(12) expect(article.hotness_score).to be(373) - expect(article.spaminess_rating).to be(2) end end @@ -38,11 +36,10 @@ RSpec.describe Articles::ScoreCalcWorker, type: :worker do expect { worker.perform(nil) }.not_to raise_error end - it "does not calculate scores", :aggregate_failures do + it "does not calculate scores" do worker.perform(nil) expect(BlackBox).not_to have_received(:article_hotness_score) - expect(BlackBox).not_to have_received(:calculate_spaminess) end end end diff --git a/spec/workers/comments/calculate_score_worker_spec.rb b/spec/workers/comments/calculate_score_worker_spec.rb index 9b51dbc09..1f7c58f60 100644 --- a/spec/workers/comments/calculate_score_worker_spec.rb +++ b/spec/workers/comments/calculate_score_worker_spec.rb @@ -12,15 +12,13 @@ RSpec.describe Comments::CalculateScoreWorker, type: :worker do before do allow(BlackBox).to receive(:comment_quality_score).and_return(7) - allow(BlackBox).to receive(:calculate_spaminess).and_return(99) end - it "updates score and spaminess_rating", :aggregate_failures do + it "updates the score" do worker.perform(comment.id) comment.reload expect(comment.score).to be(7) - expect(comment.spaminess_rating).to be(99) end it "calls save on the root comment when given a descendant comment" do