From c8c29e1b5a7db269c486a9fc9d6ec5cbf29b8e58 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 17 Jan 2022 21:14:22 +0100 Subject: [PATCH] fixed performance issue --- cookbook/helper/recipe_search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbook/helper/recipe_search.py b/cookbook/helper/recipe_search.py index 2e46bd77dc..35581b59bc 100644 --- a/cookbook/helper/recipe_search.py +++ b/cookbook/helper/recipe_search.py @@ -647,7 +647,7 @@ def _keyword_queryset(self, queryset, keyword=None): depth = getattr(keyword, 'depth', 0) + 1 steplen = depth * Keyword.steplen - return queryset.annotate(count=Coalesce(Subquery(self._recipe_count_queryset('keywords', depth, steplen)), 0) + return queryset.annotate(count=Coalesce(1, 0) ).filter(depth=depth, count__gt=0 ).values('id', 'name', 'count', 'numchild').order_by('name') @@ -655,7 +655,7 @@ def _food_queryset(self, queryset, food=None): depth = getattr(food, 'depth', 0) + 1 steplen = depth * Food.steplen - return queryset.annotate(count=Coalesce(Subquery(self._recipe_count_queryset('steps__ingredients__food', depth, steplen)), 0) + return queryset.annotate(count=Coalesce(1, 0) ).filter(depth__lte=depth, count__gt=0 ).values('id', 'name', 'count', 'numchild').order_by('name')