Skip to content

Dashboard screen performance fix #5471

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
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
12 changes: 10 additions & 2 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.db.models import Count, OuterRef, Subquery
from django.http import (
Http404,
HttpResponseBadRequest,
Expand All @@ -23,7 +24,7 @@
from vanilla import CreateView, DeleteView, DetailView, GenericView, UpdateView

from readthedocs.builds.forms import VersionForm
from readthedocs.builds.models import Version
from readthedocs.builds.models import Build, Version
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin
from readthedocs.core.utils import broadcast, prepare_build, trigger_build
from readthedocs.integrations.models import HttpExchange, Integration
Expand Down Expand Up @@ -92,7 +93,14 @@ def validate_primary_email(self, user):
notification.send()

def get_queryset(self):
return Project.objects.dashboard(self.request.user)
# Filters the builds for a perticular project.
builds = Build.objects.filter(
project=OuterRef('pk'), type='html', state='finished')
# Creates a Subquery object which returns
# the value of Build.success of the latest build.
sub_query = Subquery(builds.values('success')[:1])
return Project.objects.dashboard(self.request.user).annotate(
build_count=Count('builds'), latest_build_success=sub_query)

def get(self, request, *args, **kwargs):
self.validate_primary_email(request.user)
Expand Down
14 changes: 6 additions & 8 deletions readthedocs/templates/projects/project_dashboard_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h3>{% trans "Projects" %}</h3>
{% block project-name %}
{{ project.name }}
{% endblock %}
{% with builds=project.builds.count %}
{% with builds=project.build_count %}
{% if builds == 0 %}
<span class="right quiet">
{% trans "No builds yet" %}
Expand All @@ -80,13 +80,11 @@ <h3>{% trans "Projects" %}</h3>
{{ builds }} builds
{% endblocktrans %}
</span>
{% with build=project.get_latest_build %}
{% if build.success %}
<span class="build-state build-state-passing">{% trans "passing" %}</span>
{% else %}
<span class="build-state build-state-failing">{% trans "failing" %}</span>
{% endif %}
{% endwith %}
{% if project.latest_build_success %}
<span class="build-state build-state-passing">{% trans "passing" %}</span>
{% else %}
<span class="build-state build-state-failing">{% trans "failing" %}</span>
{% endif %}
</span>
{% endif %}
{% endwith %}
Expand Down