Skip to content
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

Profile page performance issue Fix #5472

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion readthedocs/core/templatetags/privacy_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""Template tags to query projects by privacy."""

from django import template
from django.db.models import Exists, OuterRef, Subquery

from readthedocs.builds.models import Build
from readthedocs.core.permissions import AdminPermission
from readthedocs.projects.models import Project

Expand All @@ -18,9 +20,13 @@ def is_admin(user, project):

@register.simple_tag(takes_context=True)
def get_public_projects(context, user):
builds = Build.objects.filter(project=OuterRef('pk'))
saadmk11 marked this conversation as resolved.
Show resolved Hide resolved
date_sub_query = Subquery(builds.values('date')[:1])
projects = Project.objects.for_user_and_viewer(
user=user,
viewer=context['request'].user,
)
).prefetch_related('users').annotate(
latest_build_date=date_sub_query,
good_build=Exists(builds.filter(success=True)))
context['public_projects'] = projects
return ''
7 changes: 3 additions & 4 deletions readthedocs/templates/core/project_list_detailed.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<a class="module-item-title" href="{{ project.get_absolute_url }}">{{ project.name }}</a>

{% with project.users.all as users %}

{% if users|length > 1 %}
({% for user in project.users.all|slice:":3" %}
{% if omit and user.pk != omit.pk %}
Expand All @@ -23,15 +22,15 @@
{% endif %}
{% endwith %}

{% if project.has_good_build %}
<span class="right-menu quiet">{% blocktrans with date=project.builds.all.0.date|timesince %}{{ date }} ago{% endblocktrans %}</span>
{% if project.good_build %}
<span class="right-menu quiet">{% blocktrans with date=project.latest_build_date|timesince %}{{ date }} ago{% endblocktrans %}</span>
{% else %}
<span class="right-menu quiet">{% trans "No builds" %}</span>
{% endif %}

<ul class="module-item-menu">
<li>
{% if project.has_good_build %}
{% if project.good_build %}
<a href="{{ project.get_docs_url }}">{% trans "View Docs" %}</a>
{% else %}
<a href="{{ project.get_builds_url }}">{% trans "No Docs" %}</a>
Expand Down