altered stale rfc query

This commit is contained in:
Ralf Teusner
2018-05-16 16:04:50 +02:00
parent f1830f5322
commit f7392b1c05
2 changed files with 3 additions and 2 deletions

View File

@ -8,7 +8,8 @@ class RequestForComment < ActiveRecord::Base
has_many :subscriptions
scope :unsolved, -> { where(solved: [false, nil]) }
scope :not_stale, -> { where("user_id%10 < 3").where(exercise.exercise_collections.none{|ec| ec.id = 3}) }
scope :stale, -> { where(exercise.exercise_collections.any{|ec| ec.id = 3}).where("user_id%10 < 3")}
scope :not, ->(scope) { where(scope.where_values.reduce(:and).not) }
def self.last_per_user(n = 5)
from("(#{row_number_user_sql}) as request_for_comments")

View File

@ -66,6 +66,6 @@ class Submission < ActiveRecord::Base
end
def unsolved_rfc
RequestForComment.unsolved.not_stale.where(exercise_id: exercise).where.not(question: nil).order("RANDOM()").find { | rfc_element |(rfc_element.comments_count < MAX_COMMENTS_ON_RECOMMENDED_RFC) }
RequestForComment.unsolved.not(:stale).where(exercise_id: exercise).where.not(question: nil).order("RANDOM()").find { | rfc_element |(rfc_element.comments_count < MAX_COMMENTS_ON_RECOMMENDED_RFC) }
end
end