fixed the query, removed scopes, added paranthesis for clarity.
This commit is contained in:
@ -416,7 +416,7 @@ class ExercisesController < ApplicationController
|
||||
return
|
||||
end
|
||||
|
||||
if @is_experimental_course and @rfc_group == :hide_rfc
|
||||
if @is_experimental_course and (@rfc_group == :hide_rfc)
|
||||
redirect_to_lti_return_path
|
||||
return
|
||||
end
|
||||
|
@ -8,8 +8,6 @@ class RequestForComment < ActiveRecord::Base
|
||||
has_many :subscriptions
|
||||
|
||||
scope :unsolved, -> { where(solved: [false, nil]) }
|
||||
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")
|
||||
|
@ -66,6 +66,10 @@ 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) }
|
||||
# old query
|
||||
# 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) }
|
||||
|
||||
# experimental query:
|
||||
RequestForComment.unsolved.joins('JOIN exercise_collections_exercises ece ON ece.exercise_id = request_for_comments.exercise_id').where('ece.exercise_collection_id != 3 OR user_id%10 > 3').where.not(question: nil).order("RANDOM()").to_a
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user