Skip to content

Commit c6daefe

Browse files
authored
Merge pull request readthedocs#5471 from saadmk11/dashboard-screen-performance-fix
Dashboard screen performance fix
2 parents 11a674f + 5bc9e98 commit c6daefe

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

readthedocs/projects/views/private.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.contrib import messages
88
from django.contrib.auth.decorators import login_required
99
from django.contrib.auth.models import User
10+
from django.db.models import Count, OuterRef, Subquery
1011
from django.http import (
1112
Http404,
1213
HttpResponseBadRequest,
@@ -23,7 +24,7 @@
2324
from vanilla import CreateView, DeleteView, DetailView, GenericView, UpdateView
2425

2526
from readthedocs.builds.forms import VersionForm
26-
from readthedocs.builds.models import Version
27+
from readthedocs.builds.models import Build, Version
2728
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin
2829
from readthedocs.core.utils import broadcast, prepare_build, trigger_build
2930
from readthedocs.integrations.models import HttpExchange, Integration
@@ -92,7 +93,14 @@ def validate_primary_email(self, user):
9293
notification.send()
9394

9495
def get_queryset(self):
95-
return Project.objects.dashboard(self.request.user)
96+
# Filters the builds for a perticular project.
97+
builds = Build.objects.filter(
98+
project=OuterRef('pk'), type='html', state='finished')
99+
# Creates a Subquery object which returns
100+
# the value of Build.success of the latest build.
101+
sub_query = Subquery(builds.values('success')[:1])
102+
return Project.objects.dashboard(self.request.user).annotate(
103+
build_count=Count('builds'), latest_build_success=sub_query)
96104

97105
def get(self, request, *args, **kwargs):
98106
self.validate_primary_email(request.user)

readthedocs/templates/projects/project_dashboard_base.html

+6-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h3>{% trans "Projects" %}</h3>
6666
{% block project-name %}
6767
{{ project.name }}
6868
{% endblock %}
69-
{% with builds=project.builds.count %}
69+
{% with builds=project.build_count %}
7070
{% if builds == 0 %}
7171
<span class="right quiet">
7272
{% trans "No builds yet" %}
@@ -80,13 +80,11 @@ <h3>{% trans "Projects" %}</h3>
8080
{{ builds }} builds
8181
{% endblocktrans %}
8282
</span>
83-
{% with build=project.get_latest_build %}
84-
{% if build.success %}
85-
<span class="build-state build-state-passing">{% trans "passing" %}</span>
86-
{% else %}
87-
<span class="build-state build-state-failing">{% trans "failing" %}</span>
88-
{% endif %}
89-
{% endwith %}
83+
{% if project.latest_build_success %}
84+
<span class="build-state build-state-passing">{% trans "passing" %}</span>
85+
{% else %}
86+
<span class="build-state build-state-failing">{% trans "failing" %}</span>
87+
{% endif %}
9088
</span>
9189
{% endif %}
9290
{% endwith %}

0 commit comments

Comments
 (0)