mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-10-22 23:02:20 +02:00
API: fix recipes API performance regression
Adding these extra child items to the standard "recipes" viewset (which
we did recently in 684a06a383) means that
some current usage is impractical due to the size of the returned list
of items. Instead, create a recipesExtended viewset, move the new child
items to that and add pagination to avoid result size issues.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
73198bd548
commit
ee1ff214a0
|
|
@ -1,7 +1,16 @@
|
|||
# OpenEmbedded Layer Index REST API implementation
|
||||
#
|
||||
# Copyright (C) 2014, 2016-2019 Intel Corporation
|
||||
#
|
||||
# Licensed under the MIT license, see COPYING.MIT for details
|
||||
|
||||
from layerindex.models import Branch, LayerItem, LayerMaintainer, YPCompatibleVersion, LayerNote, LayerBranch, LayerDependency, Recipe, Machine, Distro, BBClass, Source, Patch, PackageConfig, StaticBuildDep, DynamicBuildDep, RecipeFileDependency, BBAppend, IncFile
|
||||
from rest_framework import viewsets, serializers
|
||||
from rest_framework import viewsets, serializers, pagination
|
||||
from layerindex.querysethelper import params_to_queryset, get_search_tuple
|
||||
|
||||
class LayerIndexPagination(pagination.PageNumberPagination):
|
||||
page_size = 200
|
||||
|
||||
class DynamicFieldsModelSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
A ModelSerializer that takes an additional "fields" argument that
|
||||
|
|
@ -114,6 +123,15 @@ class RecipeSerializer(serializers.ModelSerializer):
|
|||
model = Recipe
|
||||
fields = '__all__'
|
||||
|
||||
class RecipeViewSet(ParametricSearchableModelViewSet):
|
||||
queryset = Recipe.objects.all()
|
||||
serializer_class = RecipeSerializer
|
||||
|
||||
class RecipeExtendedSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = '__all__'
|
||||
|
||||
sources = serializers.SerializerMethodField()
|
||||
patches = serializers.SerializerMethodField()
|
||||
package_configs = serializers.SerializerMethodField()
|
||||
|
|
@ -143,9 +161,10 @@ class RecipeSerializer(serializers.ModelSerializer):
|
|||
serializer = RecipeFileDependencySerializer(instance=qs, many=True, read_only=True, fields=('layerbranch', 'path'))
|
||||
return serializer.data
|
||||
|
||||
class RecipeViewSet(ParametricSearchableModelViewSet):
|
||||
class RecipeExtendedViewSet(ParametricSearchableModelViewSet):
|
||||
queryset = Recipe.objects.all()
|
||||
serializer_class = RecipeSerializer
|
||||
serializer_class = RecipeExtendedSerializer
|
||||
pagination_class = LayerIndexPagination
|
||||
|
||||
class MachineSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ router.register(r'layerDependencies', restviews.LayerDependencyViewSet)
|
|||
router.register(r'layerMaintainers', restviews.LayerMaintainerViewSet)
|
||||
router.register(r'layerNotes', restviews.LayerNoteViewSet)
|
||||
router.register(r'recipes', restviews.RecipeViewSet)
|
||||
router.register(r'recipesExtended', restviews.RecipeExtendedViewSet)
|
||||
router.register(r'machines', restviews.MachineViewSet)
|
||||
router.register(r'distros', restviews.DistroViewSet)
|
||||
router.register(r'classes', restviews.ClassViewSet)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user