[layerindex-web,1/3] API: fix recipes API performance regression

Submitted by Paul Eggleton on Sept. 16, 2019, 5:19 a.m. | Patch ID: 165007

Details

Message ID ee1ff214a0d8795e7160845969a9da4b9475007a.1568611075.git.paul.eggleton@linux.intel.com
State New
Headers show

Commit Message

Paul Eggleton Sept. 16, 2019, 5:19 a.m.
Adding these extra child items to the standard "recipes" viewset (which
we did recently in 684a06a383fd2a8da80490dff5f0dbc47750934e) 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>
---
 layerindex/restviews.py | 25 ++++++++++++++++++++++---
 layerindex/urls.py      |  1 +
 2 files changed, 23 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/layerindex/restviews.py b/layerindex/restviews.py
index 96c24ea3..7de4cd7d 100644
--- a/layerindex/restviews.py
+++ b/layerindex/restviews.py
@@ -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:
diff --git a/layerindex/urls.py b/layerindex/urls.py
index dec99585..13f42c92 100644
--- a/layerindex/urls.py
+++ b/layerindex/urls.py
@@ -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)