Reduce BOM listing time to ~1.8s

This commit is contained in:
Oliver Walters 2019-05-20 08:31:03 +10:00
parent cee1062b51
commit 5055226490
2 changed files with 12 additions and 4 deletions

View File

@ -203,10 +203,14 @@ class BomList(generics.ListCreateAPIView):
- GET: Return list of BomItem objects
- POST: Create a new BomItem object
"""
queryset = BomItem.objects.all()
serializer_class = BomItemSerializer
def get_queryset(self):
queryset = BomItem.objects.all()
queryset = self.get_serializer_class().setup_eager_loading(queryset)
return queryset
permission_classes = [
permissions.IsAuthenticatedOrReadOnly,
]

View File

@ -112,16 +112,20 @@ class PartStarSerializer(InvenTreeModelSerializer):
class BomItemSerializer(InvenTreeModelSerializer):
""" Serializer for BomItem object """
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
price_info = serializers.CharField(read_only=True)
@staticmethod
def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('sub_part')
queryset = queryset.prefetch_related('sub_part__category')
return queryset
class Meta:
model = BomItem
fields = [
'pk',
'part',
'part_detail',
'sub_part',
'sub_part_detail',
'quantity',