From 29be6f8209515ff173510301cc8b5453ae440cbd Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Fri, 31 Aug 2012 15:16:31 -0400 Subject: [PATCH 1/2] Prefetch user groups to speed up auth checks required to render Progress page view for students --- lms/djangoapps/courseware/access.py | 2 +- lms/djangoapps/courseware/views.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py index dbe4ff376d..91c769f90a 100644 --- a/lms/djangoapps/courseware/access.py +++ b/lms/djangoapps/courseware/access.py @@ -321,7 +321,7 @@ def _has_staff_access_to_location(user, location): return True # If not global staff, is the user in the Auth group for this class? - user_groups = [x[1] for x in user.groups.values_list()] + user_groups = [g.name for g in user.groups.all()] staff_group = _course_staff_group_name(location) if staff_group in user_groups: debug("Allow: user in group %s", staff_group) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 92f6716320..dab04a0957 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -327,6 +327,7 @@ def progress(request, course_id, student_id=None): # NOTE: To make sure impersonation by instructor works, use # student instead of request.user in the rest of the function. + student = User.objects.prefetch_related("groups").get(id=student.id) student_module_cache = StudentModuleCache.cache_for_descriptor_descendents( course_id, student, course) From 04439a321791ef58a8e2627a185ea8fc91775c3f Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Fri, 31 Aug 2012 15:20:13 -0400 Subject: [PATCH 2/2] add comments explaining prefetch need --- lms/djangoapps/courseware/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index dab04a0957..6b77792203 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -327,6 +327,9 @@ def progress(request, course_id, student_id=None): # NOTE: To make sure impersonation by instructor works, use # student instead of request.user in the rest of the function. + + # The pre-fetching of groups is done to make auth checks not require an + # additional DB lookup (this kills the Progress page in particular). student = User.objects.prefetch_related("groups").get(id=student.id) student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(