2019-05-12 21:55:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-02 00:01:53 -04:00
|
|
|
class Jobs::ReviewablePriorities < ::Jobs::Scheduled
|
2019-05-07 13:25:11 -04:00
|
|
|
every 1.day
|
|
|
|
|
2019-09-19 14:07:56 -04:00
|
|
|
# We need this many reviewables before we'll calculate priorities
|
2019-09-19 13:42:50 -04:00
|
|
|
def self.min_reviewables
|
|
|
|
15
|
|
|
|
end
|
|
|
|
|
2019-09-19 14:07:56 -04:00
|
|
|
# We want to look at scores for items with this many reviewables (flags) attached
|
|
|
|
def self.target_count
|
|
|
|
2
|
|
|
|
end
|
|
|
|
|
2019-05-07 13:25:11 -04:00
|
|
|
def execute(args)
|
2021-04-23 14:34:24 -04:00
|
|
|
min_priority_threshold = SiteSetting.reviewable_low_priority_threshold
|
2021-12-08 12:12:24 -05:00
|
|
|
reviewable_count = Reviewable.approved.where("score > ?", min_priority_threshold).count
|
2021-05-10 13:09:04 -04:00
|
|
|
return if reviewable_count < self.class.min_reviewables
|
2021-04-23 14:34:24 -04:00
|
|
|
|
|
|
|
res =
|
|
|
|
DB.query_single(
|
|
|
|
<<~SQL,
|
2019-05-16 13:45:20 -04:00
|
|
|
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
|
2019-09-19 14:07:56 -04:00
|
|
|
FROM (
|
|
|
|
SELECT r.score
|
|
|
|
FROM reviewables AS r
|
|
|
|
INNER JOIN reviewable_scores AS rs ON rs.reviewable_id = r.id
|
2021-05-10 13:09:04 -04:00
|
|
|
WHERE r.score > :min_priority AND r.status = 1
|
2019-09-19 14:07:56 -04:00
|
|
|
GROUP BY r.id
|
|
|
|
HAVING COUNT(*) >= :target_count
|
|
|
|
) AS x
|
2019-05-07 13:25:11 -04:00
|
|
|
SQL
|
2021-04-23 14:34:24 -04:00
|
|
|
target_count: self.class.target_count,
|
|
|
|
min_priority: min_priority_threshold,
|
2023-01-09 07:20:10 -05:00
|
|
|
)
|
2019-05-07 13:25:11 -04:00
|
|
|
|
2019-09-19 14:07:56 -04:00
|
|
|
return unless res && res.size == 2
|
|
|
|
|
2019-05-22 17:23:45 -04:00
|
|
|
medium, high = res
|
|
|
|
|
2021-04-23 14:34:24 -04:00
|
|
|
Reviewable.set_priorities(low: min_priority_threshold, medium: medium, high: high)
|
2019-05-07 13:25:11 -04:00
|
|
|
end
|
|
|
|
end
|