mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 18:36:35 +08:00
FIX: Require a min amount of reviewables before calculating thresholds
On forums with very few flags you don't want to calculate averages because they won't be very useful. Stick with the defaults until we hit 15 reviewables at least.
This commit is contained in:
parent
3c6a5836c2
commit
d5b52abf2f
|
@ -3,7 +3,12 @@
|
|||
class Jobs::ReviewablePriorities < Jobs::Scheduled
|
||||
every 1.day
|
||||
|
||||
def self.min_reviewables
|
||||
15
|
||||
end
|
||||
|
||||
def execute(args)
|
||||
return unless Reviewable.where('score > 0').count >= self.class.min_reviewables
|
||||
|
||||
# We calculate the percentiles here for medium and high. Low is always 0 (all)
|
||||
res = DB.query_single(<<~SQL)
|
||||
|
|
|
@ -4,21 +4,32 @@ require 'rails_helper'
|
|||
|
||||
describe Jobs::ReviewablePriorities do
|
||||
|
||||
it "will set priorities based on the maximum score" do
|
||||
(1..6).each { |i| Fabricate(:reviewable, score: i) }
|
||||
it "needs returns 0s with no existing reviewables" do
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
||||
expect(Reviewable.min_score_for_priority(:medium)).to eq(3.0)
|
||||
expect(Reviewable.min_score_for_priority('medium')).to eq(3.0)
|
||||
expect(Reviewable.min_score_for_priority(:high)).to eq(6.0)
|
||||
end
|
||||
|
||||
it "will return 0 if no reviewables exist" do
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
||||
expect(Reviewable.min_score_for_priority(:medium)).to eq(0.0)
|
||||
expect(Reviewable.min_score_for_priority(:high)).to eq(0.0)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
||||
end
|
||||
|
||||
it "needs a minimum amount of reviewables before it calculates anything" do
|
||||
(1..5).each { |i| Fabricate(:reviewable, score: i) }
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
||||
expect(Reviewable.min_score_for_priority(:medium)).to eq(0.0)
|
||||
expect(Reviewable.min_score_for_priority(:high)).to eq(0.0)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
||||
end
|
||||
|
||||
it "will set priorities based on the maximum score" do
|
||||
(1..Jobs::ReviewablePriorities.min_reviewables).each { |i| Fabricate(:reviewable, score: i) }
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
||||
expect(Reviewable.min_score_for_priority(:medium)).to eq(8.0)
|
||||
expect(Reviewable.min_score_for_priority('medium')).to eq(8.0)
|
||||
expect(Reviewable.min_score_for_priority(:high)).to eq(13.0)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(8.66)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user