ingredient related recipes performance
This commit is contained in:
parent
38010117e5
commit
1efcf386e2
@ -627,7 +627,11 @@ class IngredientSimpleSerializer(WritableNestedModelSerializer):
|
||||
nutritions = serializers.SerializerMethodField('get_nutritions')
|
||||
|
||||
def get_used_in_recipes(self, obj):
|
||||
return list(Recipe.objects.filter(steps__ingredients=obj.id).values('id', 'name'))
|
||||
used_in = []
|
||||
for s in obj.step_set.all():
|
||||
for r in s.recipe_set.all():
|
||||
used_in.append({'id':r.id,'name':r.name})
|
||||
return used_in
|
||||
|
||||
def get_conversions(self, obj):
|
||||
conversions = []
|
||||
|
@ -797,7 +797,10 @@ class RecipeViewSet(viewsets.ModelViewSet):
|
||||
if self.detail: # if detail request and not list, private condition is verified by permission class
|
||||
if not share: # filter for space only if not shared
|
||||
self.queryset = self.queryset.filter(space=self.request.space).prefetch_related('steps', 'keywords',
|
||||
'shared', 'steps__ingredients',
|
||||
'shared',
|
||||
'steps__ingredients',
|
||||
'steps__ingredients__step_set',
|
||||
'steps__ingredients__step_set__recipe_set',
|
||||
'steps__ingredients__food',
|
||||
'steps__ingredients__food__inherit_fields',
|
||||
'steps__ingredients__food__supermarket_category',
|
||||
|
Loading…
Reference in New Issue
Block a user