Tweak calculation for reviewable sensitivities/priorities

Tweak calculation for reviewable sensitivities/priorities

Previously, calculating thresholds for reviewables was done based on the 50th and 85th percentile across all reviewables. However, many forum owners provided feedback that these thresholds were too easy to hit, in particular when it came to auto hiding content.

The calculation has been adjusted to base the priorities on reviewables that have a minimum of 2 scores (flags). This should push the amount of flags required to hide something higher then before.

diff --git a/app/jobs/scheduled/reviewable_priorities.rb b/app/jobs/scheduled/reviewable_priorities.rb
index e4a57bb..b1133a8 100644
--- a/app/jobs/scheduled/reviewable_priorities.rb
+++ b/app/jobs/scheduled/reviewable_priorities.rb
@@ -3,20 +3,33 @@
 class Jobs::ReviewablePriorities < Jobs::Scheduled
   every 1.day
 
+  # We need this many reviewables before we'll calculate priorities
   def self.min_reviewables
     15
   end
 
+  # We want to look at scores for items with this many reviewables (flags) attached
+  def self.target_count
+    2
+  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)
+    res = DB.query_single(<<~SQL, target_count: self.class.target_count)
       SELECT COALESCE(PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY score), 0.0) AS medium,
         COALESCE(PERCENTILE_DISC(0.85) WITHIN GROUP (ORDER BY score), 0.0) AS high
-        FROM reviewables
+      FROM (
+        SELECT r.score
+        FROM reviewables AS r
+        INNER JOIN reviewable_scores AS rs ON rs.reviewable_id = r.id
+        GROUP BY r.id
+        HAVING COUNT(*) >= :target_count
+      ) AS x
     SQL
 
+    return unless res && res.size == 2
+
     medium, high = res
 
     Reviewable.set_priorities(medium: medium, high: high)
diff --git a/spec/jobs/reviewable_priorities_spec.rb b/spec/jobs/reviewable_priorities_spec.rb
index 076fba4..2227637 100644
--- a/spec/jobs/reviewable_priorities_spec.rb
+++ b/spec/jobs/reviewable_priorities_spec.rb
@@ -12,8 +12,20 @@ describe Jobs::ReviewablePriorities do
     expect(Reviewable.score_required_to_hide_post).to eq(8.33)
   end
 
+  fab!(:u0) { Fabricate(:user) }
+  fab!(:u1) { Fabricate(:user) }
+
+  def create_reviewables(count)
+    (1..count).each do |i|
+      r = Fabricate(:reviewable_flagged_post)
+      r.add_score(u0, PostActionType.types[:off_topic])
+      r.add_score(u1, PostActionType.types[:off_topic])
+      r.update!(score: i)
+    end
+  end
+
   it "needs a minimum amount of reviewables before it calculates anything" do
-    (1..5).each { |i| Fabricate(:reviewable, score: i) }
+    create_reviewables(5)
     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)
@@ -22,7 +34,7 @@ describe Jobs::ReviewablePriorities do
   end
 
   it "will set priorities based on the maximum score" do
-    (1..Jobs::ReviewablePriorities.min_reviewables).each { |i| Fabricate(:reviewable, score: i) }
+    create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
     Jobs::ReviewablePriorities.new.execute({})
 
     expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)

GitHub sha: d251f12c

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there: