mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Significant query speed improvements to stock list API
- Thanks, django-debug-toolbar! - Gah, django DRF is the worst. Enforcing a PrimaryKeyRelatedSerializer seems to really improve speed
This commit is contained in:
parent
411e7507a3
commit
2f77007dbe
@ -338,11 +338,6 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
|
|
||||||
page = self.paginate_queryset(queryset)
|
|
||||||
if page is not None:
|
|
||||||
serializer = self.get_serializer(page, many=True)
|
|
||||||
return self.get_paginated_response(serializer.data)
|
|
||||||
|
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
serializer = self.get_serializer(queryset, many=True)
|
||||||
|
|
||||||
data = serializer.data
|
data = serializer.data
|
||||||
@ -363,6 +358,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
part_ids.add(part)
|
part_ids.add(part)
|
||||||
|
|
||||||
sp = item['supplier_part']
|
sp = item['supplier_part']
|
||||||
|
|
||||||
if sp:
|
if sp:
|
||||||
supplier_part_ids.add(sp)
|
supplier_part_ids.add(sp)
|
||||||
|
|
||||||
@ -434,6 +430,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
def get_queryset(self, *args, **kwargs):
|
def get_queryset(self, *args, **kwargs):
|
||||||
|
|
||||||
queryset = super().get_queryset(*args, **kwargs)
|
queryset = super().get_queryset(*args, **kwargs)
|
||||||
|
|
||||||
queryset = StockItemSerializer.prefetch_queryset(queryset)
|
queryset = StockItemSerializer.prefetch_queryset(queryset)
|
||||||
queryset = StockItemSerializer.annotate_queryset(queryset)
|
queryset = StockItemSerializer.annotate_queryset(queryset)
|
||||||
|
|
||||||
|
@ -99,15 +99,34 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
belongs_to = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
|
build_order = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
|
customer = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
|
location = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
|
in_stock = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
|
sales_order = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
supplier_part = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
|
||||||
supplier_part_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
|
supplier_part_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
|
||||||
|
|
||||||
|
part = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||||
|
|
||||||
|
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
||||||
|
|
||||||
tracking_items = serializers.IntegerField(source='tracking_info_count', read_only=True, required=False)
|
tracking_items = serializers.IntegerField(source='tracking_info_count', read_only=True, required=False)
|
||||||
|
|
||||||
quantity = serializers.FloatField()
|
quantity = serializers.FloatField()
|
||||||
|
|
||||||
allocated = serializers.FloatField(source='allocation_count', required=False)
|
allocated = serializers.FloatField(source='allocation_count', required=False)
|
||||||
|
|
||||||
serial = serializers.IntegerField(required=False)
|
serial = serializers.IntegerField(required=False)
|
||||||
@ -140,9 +159,9 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
fields = [
|
fields = [
|
||||||
'allocated',
|
'allocated',
|
||||||
'batch',
|
'batch',
|
||||||
'build_order',
|
|
||||||
'belongs_to',
|
'belongs_to',
|
||||||
'customer',
|
'customer',
|
||||||
|
'build_order',
|
||||||
'in_stock',
|
'in_stock',
|
||||||
'link',
|
'link',
|
||||||
'location',
|
'location',
|
||||||
@ -155,10 +174,10 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
'required_tests',
|
'required_tests',
|
||||||
'sales_order',
|
'sales_order',
|
||||||
'serial',
|
'serial',
|
||||||
'supplier_part',
|
|
||||||
'supplier_part_detail',
|
|
||||||
'status',
|
'status',
|
||||||
'status_text',
|
'status_text',
|
||||||
|
'supplier_part',
|
||||||
|
'supplier_part_detail',
|
||||||
'tracking_items',
|
'tracking_items',
|
||||||
'uid',
|
'uid',
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user