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