Skip to content

Optimize the version list screen #5460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions readthedocs/core/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class AdminPermissionBase:

@classmethod
def is_admin(cls, user, project):
# This explicitly uses "user in project.users.all" so that
# users on projects can be cached using prefetch_related or prefetch_related_objects
return user in project.users.all() or user.is_superuser

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.files.storage import get_storage_class
from django.db.models import prefetch_related_objects
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
Expand Down Expand Up @@ -271,6 +272,9 @@ def project_versions(request, project_slug):
if wiped and wiped_version.count():
messages.success(request, 'Version wiped: ' + wiped)

# Optimize project permission checks
prefetch_related_objects([project], 'users')

return render(
request,
'projects/project_version_list.html',
Expand Down