improve performance of needs_grading_count in course_json
test plan: * regression test 'needs_grading_count' includes in course index api calls closes #CNVS-21156 Change-Id: Ic20704ec3704ed9e8230ad424cad2e5e92fccb68 Reviewed-on: https://gerrit.instructure.com/56465 Tested-by: Jenkins Reviewed-by: Ethan Vizitei <evizitei@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
58fdd31928
commit
5067afc590
|
@ -1,10 +1,40 @@
|
|||
module Assignments
|
||||
class NeedsGradingCountQuery
|
||||
attr_reader :assignment, :user
|
||||
|
||||
def initialize(_assignment, _user)
|
||||
# holds values so we don't have to recompute them over and over again
|
||||
class CourseProxy
|
||||
attr_reader :course, :user
|
||||
|
||||
def initialize(_course, _user)
|
||||
@course = _course
|
||||
@user = _user
|
||||
end
|
||||
|
||||
def da_enabled?
|
||||
@da_enabled ||= course.feature_enabled?(:differentiated_assignments)
|
||||
end
|
||||
|
||||
def section_visibilities
|
||||
@section_visibilities ||= course.section_visibilities_for(user)
|
||||
end
|
||||
|
||||
def visibility_level
|
||||
@visibility_level ||= course.enrollment_visibility_level_for(user, section_visibilities)
|
||||
end
|
||||
|
||||
def visible_section_ids
|
||||
@visible_section_ids ||= section_visibilities.map{|v| v[:course_section_id]}
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :assignment, :user, :course_proxy
|
||||
|
||||
delegate :course, :da_enabled?, :section_visibilities, :visibility_level, :visible_section_ids, :to => :course_proxy
|
||||
|
||||
def initialize(_assignment, _user, _course_proxy=nil)
|
||||
@assignment = _assignment
|
||||
@user = _user
|
||||
@course_proxy = _course_proxy || CourseProxy.new(@assignment.context, @user)
|
||||
end
|
||||
|
||||
def count
|
||||
|
@ -76,25 +106,5 @@ module Assignments
|
|||
def joined_submissions
|
||||
assignment.submissions.joins("INNER JOIN enrollments e ON e.user_id = submissions.user_id")
|
||||
end
|
||||
|
||||
def visible_section_ids
|
||||
section_visibilities.map{|v| v[:course_section_id]}
|
||||
end
|
||||
|
||||
def visibility_level
|
||||
course.enrollment_visibility_level_for(user, section_visibilities)
|
||||
end
|
||||
|
||||
def section_visibilities
|
||||
course.section_visibilities_for(user)
|
||||
end
|
||||
|
||||
def course
|
||||
assignment.context
|
||||
end
|
||||
|
||||
def da_enabled?
|
||||
course.feature_enabled?(:differentiated_assignments)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -71,7 +71,8 @@ module Api::V1
|
|||
|
||||
def needs_grading_count(enrollments, course)
|
||||
if include_grading && enrollments && enrollments.any? { |e| e.participating_instructor? }
|
||||
course.assignments.active.to_a.sum{|a| Assignments::NeedsGradingCountQuery.new(a, user).count }
|
||||
proxy = Assignments::NeedsGradingCountQuery::CourseProxy.new(course, user)
|
||||
course.assignments.active.to_a.sum{|a| Assignments::NeedsGradingCountQuery.new(a, user, proxy).count }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue