mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
d5b52abf2f
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.
25 lines
659 B
Ruby
25 lines
659 B
Ruby
# frozen_string_literal: true
|
|
|
|
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)
|
|
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
|
|
SQL
|
|
|
|
medium, high = res
|
|
|
|
Reviewable.set_priorities(medium: medium, high: high)
|
|
end
|
|
end
|