Class: Jobs::ReviewablePriorities
- Defined in:
- app/jobs/scheduled/reviewable_priorities.rb
Class Method Summary collapse
-
.min_reviewables ⇒ Object
We need this many reviewables before we’ll calculate priorities.
-
.target_count ⇒ Object
We want to look at scores for items with this many reviewables (flags) attached.
Instance Method Summary collapse
Methods inherited from Scheduled
Methods inherited from Base
acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately
Class Method Details
.min_reviewables ⇒ Object
We need this many reviewables before we’ll calculate priorities
7 8 9 |
# File 'app/jobs/scheduled/reviewable_priorities.rb', line 7 def self.min_reviewables 15 end |
.target_count ⇒ Object
We want to look at scores for items with this many reviewables (flags) attached
12 13 14 |
# File 'app/jobs/scheduled/reviewable_priorities.rb', line 12 def self.target_count 2 end |
Instance Method Details
#execute(args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/jobs/scheduled/reviewable_priorities.rb', line 16 def execute(args) min_priority_threshold = SiteSetting.reviewable_low_priority_threshold reviewable_count = Reviewable.approved.where("score > ?", min_priority_threshold).count return if reviewable_count < self.class.min_reviewables 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 ( SELECT r.score FROM reviewables AS r INNER JOIN reviewable_scores AS rs ON rs.reviewable_id = r.id WHERE r.score > :min_priority AND r.status = 1 GROUP BY r.id HAVING COUNT(*) >= :target_count ) AS x SQL target_count: self.class.target_count, min_priority: min_priority_threshold, ) return unless res && res.size == 2 medium, high = res Reviewable.set_priorities(low: min_priority_threshold, medium: medium, high: high) end |