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 <jgaskins@hey.com> * Remove references to calculate_spaminess * Update app/workers/comments/calculate_score_worker.rb Co-authored-by: Jamie Gaskins <jgaskins@hey.com> Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Co-authored-by: Jamie Gaskins <jgaskins@hey.com> Co-authored-by: Jamie Gaskins <jamie@forem.com>
This commit is contained in:
parent
b05d14dfcd
commit
6818ef3ed0
7 changed files with 6 additions and 38 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue