Revert "Improve the performance of access checking for a specific user in CourseViewList by prefetching data"
This reverts commit a2a340bcd0.
This commit is contained in:
@@ -121,14 +121,7 @@ class Role(models.Model):
|
||||
"""
|
||||
Returns True if the user has one of the given roles for the given course
|
||||
"""
|
||||
if 'roles' in getattr(user, '_prefetched_objects_cache', {}):
|
||||
# Don't blow up the prefetch cache
|
||||
return any(
|
||||
role.course_id == course_id and role.name in role_names
|
||||
for role in user.roles.all()
|
||||
)
|
||||
else:
|
||||
return user.roles.filter(course_id=course_id, name__in=role_names).exists()
|
||||
return Role.objects.filter(course_id=course_id, name__in=role_names, users=user).exists()
|
||||
|
||||
|
||||
class Permission(models.Model):
|
||||
|
||||
@@ -1195,19 +1195,13 @@ class CourseEnrollment(models.Model):
|
||||
if user.is_anonymous:
|
||||
return None
|
||||
try:
|
||||
if 'courseenrollment' in getattr(user, '_prefetched_objects_cache', {}):
|
||||
for enrollment in user.courseenrollment_set.all():
|
||||
if enrollment.course_id == course_key:
|
||||
return enrollment
|
||||
return None
|
||||
else:
|
||||
query = cls.objects
|
||||
if select_related is not None:
|
||||
query = query.select_related(*select_related)
|
||||
return query.get(
|
||||
user=user,
|
||||
course_id=course_key
|
||||
)
|
||||
query = cls.objects
|
||||
if select_related is not None:
|
||||
query = query.select_related(*select_related)
|
||||
return query.get(
|
||||
user=user,
|
||||
course_id=course_key
|
||||
)
|
||||
except cls.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user