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

Dashboard: index page is slow #9804

Open
humitos opened this issue Dec 13, 2022 · 0 comments
Open

Dashboard: index page is slow #9804

humitos opened this issue Dec 13, 2022 · 0 comments
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code

Comments

@humitos
Copy link
Member

humitos commented Dec 13, 2022

Accessing https://readthedocs.org/dashboard/ while logged in, I can see that it executes 10 SQL queries and they take 2119.93ms. The slowest query here is the one that prefetches the latest build for each of the project the user has access to.

def prefetch_latest_build(self):
"""
Prefetch "latest build" for each project.
.. note::
This should come after any filtering.
"""
from readthedocs.builds.models import Build
# Prefetch the latest build for each project.
subquery = Subquery(
Build.internal.filter(
project=OuterRef('project_id')
).order_by('-date').values_list('id', flat=True)[:1]
)
latest_build = Prefetch(
'builds',
Build.internal.filter(pk__in=subquery),
to_attr=self.model.LATEST_BUILD_CACHE,
)
return self.prefetch_related(latest_build)

The latest build is used in the template to show when it was built for the last time and also if it has success or failed:

{% with build=project.get_latest_build %}
<span class="right quiet">
{% if build %}
<time class="build-count" datetime="{{ build.date|date:"c" }}" title="{{ build.date|date:"DATETIME_FORMAT" }}">
<small>{% blocktrans with date=build.date|timesince %}{{ date }} ago{% endblocktrans %}</small>
</time>
{% if build.success %}
<span class="build-state build-state-passing">{% trans "passing" %}</span>
{% else %}
<span class="build-state build-state-failing">{% trans "failing" %}</span>
{# TODO: What whould be show here when "not build.sucess and cancelled"? #}
{% endif %}
{% else %}
<span>{% trans "No builds yet" %}</span>
{% endif %}

@humitos humitos added Improvement Minor improvement to code Accepted Accepted issue on our roadmap labels Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code
Projects
None yet
Development

No branches or pull requests

1 participant