From c39cd5b77c282b1c599aea6ec1426d60184c1e6f Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Tue, 26 May 2020 11:55:40 -0700 Subject: [PATCH] Revert "Merge pull request #7101 from readthedocs/show-last-total" This reverts commit 204bc4398e60ec40a4476df79824dc8b33782c84, reversing changes made to 0d7901eba9a213fb93a41259fd471219516e380b. --- readthedocs/projects/views/private.py | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/readthedocs/projects/views/private.py b/readthedocs/projects/views/private.py index 8ef7570ebfe..b23a4ef3654 100644 --- a/readthedocs/projects/views/private.py +++ b/readthedocs/projects/views/private.py @@ -6,7 +6,7 @@ from allauth.socialaccount.models import SocialAccount from django.conf import settings from django.contrib import messages -from django.db.models import Count, OuterRef, Subquery +from django.db.models import Count from django.http import ( Http404, HttpResponseBadRequest, @@ -39,7 +39,10 @@ Version, VersionAutomationRule, ) -from readthedocs.core.mixins import ListViewWithForm, PrivateViewMixin +from readthedocs.core.mixins import ( + ListViewWithForm, + PrivateViewMixin, +) from readthedocs.core.utils import broadcast, trigger_build from readthedocs.core.utils.extend import SettingsOverrideObject from readthedocs.integrations.models import HttpExchange, Integration @@ -993,21 +996,18 @@ def get_context_data(self, **kwargs): project.slug, ) - project_queries = SearchQuery.objects.filter(project=project) - last_total_results = ( - project_queries.filter(query=OuterRef('query')) - .order_by('-modified') - .values('total_results') - ) - queries = ( - project_queries.values('query') - .annotate( - count=Count('id'), - total_results=Subquery(last_total_results[:1]) + queries = [] + qs = SearchQuery.objects.filter(project=project) + if qs.exists(): + qs = ( + qs.values('query') + .annotate(count=Count('id')) + .order_by('-count', 'query') + .values_list('query', 'count', 'total_results') ) - .order_by('-count', 'query') - .values_list('query', 'count', 'total_results') - )[:100] + + # only show top 100 queries + queries = qs[:100] context.update( {