-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Optimizations and UX improvements to the dashboard screen #5637
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
Changes from 1 commit
47f3540
a3793d9
c032b12
943935d
95948b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"""Project model QuerySet classes.""" | ||
|
||
from django.db import models | ||
from django.db.models import Q | ||
from django.db.models import Q, OuterRef, Subquery, Prefetch | ||
from guardian.shortcuts import get_objects_for_user | ||
|
||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
|
@@ -80,7 +80,22 @@ def is_active(self, project): | |
# Aliases | ||
|
||
def dashboard(self, user=None): | ||
return self.for_admin_user(user) | ||
"""Get the projects for this user including the latest build""" | ||
from readthedocs.builds.models import Build | ||
|
||
projects = self.for_admin_user(user) | ||
|
||
# Prefetch the latest build for each project. | ||
subquery = Subquery( | ||
Build.objects.filter(project=OuterRef('project_id')).values_list('id', flat=True)[:1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not needed because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't necessary due to the default ordering but maybe it is best to be explicit. |
||
) | ||
latest_build = Prefetch( | ||
'builds', | ||
Build.objects.filter(pk__in=subquery), | ||
to_attr='_latest_build', | ||
) | ||
|
||
return projects.prefetch_related(latest_build) | ||
|
||
def api(self, user=None): | ||
return self.public(user) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be useful to extend this comment indicating where this comes from (dashboard queryset), why it's needed or similar since the source it's in another file and I think we will not find this quickly when reading the code later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. How about after #5472 is merged I'll refactor this slightly to have a class variable for caching it.