mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Reduce response time for stock list
Initial time - 6.2s After prefetch - 4.3s
This commit is contained in:
parent
5055226490
commit
fc75ab7420
@ -119,6 +119,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
def setup_eager_loading(queryset):
|
def setup_eager_loading(queryset):
|
||||||
queryset = queryset.prefetch_related('sub_part')
|
queryset = queryset.prefetch_related('sub_part')
|
||||||
queryset = queryset.prefetch_related('sub_part__category')
|
queryset = queryset.prefetch_related('sub_part__category')
|
||||||
|
queryset = queryset.prefetch_related('sub_part__locations')
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -282,6 +282,9 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
if supplier_id:
|
if supplier_id:
|
||||||
stock_list = stock_list.filter(supplier_part__supplier=supplier_id)
|
stock_list = stock_list.filter(supplier_part__supplier=supplier_id)
|
||||||
|
|
||||||
|
# Pre-fetch related objects for better response time
|
||||||
|
stock_list = self.get_serializer_class().setup_eager_loading(stock_list)
|
||||||
|
|
||||||
return stock_list
|
return stock_list
|
||||||
|
|
||||||
serializer_class = StockItemSerializer
|
serializer_class = StockItemSerializer
|
||||||
|
@ -60,6 +60,15 @@ class StockItemSerializer(serializers.ModelSerializer):
|
|||||||
location = LocationBriefSerializer(many=False, read_only=True)
|
location = LocationBriefSerializer(many=False, 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)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setup_eager_loading(queryset):
|
||||||
|
queryset = queryset.prefetch_related('part')
|
||||||
|
queryset = queryset.prefetch_related('part__locations')
|
||||||
|
queryset = queryset.prefetch_related('part__category')
|
||||||
|
queryset = queryset.prefetch_related('location')
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StockItem
|
model = StockItem
|
||||||
fields = [
|
fields = [
|
||||||
|
Loading…
Reference in New Issue
Block a user