mirror of
https://github.com/inventree/InvenTree.git
synced 2026-05-23 09:35:30 +00:00
Fix: Treegrid is loading an eternity for huge amounts of data (#3451)
* Added default max depth and lazy loading to StorageLocation * Added default max depth and lazy loading to PartCategory * Update API version * lint: fix * Added INVENTREE_TREE_DEPTH setting * Refactored int conversion into own helper function * Added tests
This commit is contained in:
@@ -26,7 +26,7 @@ from InvenTree.api import (APIDownloadMixin, AttachmentMixin,
|
||||
ListCreateDestroyAPIView)
|
||||
from InvenTree.filters import InvenTreeOrderingFilter
|
||||
from InvenTree.helpers import (DownloadFile, extract_serial_numbers, isNull,
|
||||
str2bool)
|
||||
str2bool, str2int)
|
||||
from InvenTree.mixins import (CreateAPI, ListAPI, ListCreateAPI, RetrieveAPI,
|
||||
RetrieveUpdateAPI, RetrieveUpdateDestroyAPI)
|
||||
from order.models import PurchaseOrder, SalesOrder, SalesOrderAllocation
|
||||
@@ -241,6 +241,8 @@ class StockLocationList(ListCreateAPI):
|
||||
|
||||
cascade = str2bool(params.get('cascade', False))
|
||||
|
||||
depth = str2int(params.get('depth', None))
|
||||
|
||||
# Do not filter by location
|
||||
if loc_id is None:
|
||||
pass
|
||||
@@ -251,6 +253,9 @@ class StockLocationList(ListCreateAPI):
|
||||
if not cascade:
|
||||
queryset = queryset.filter(parent=None)
|
||||
|
||||
if cascade and depth is not None:
|
||||
queryset = queryset.filter(level__lte=depth)
|
||||
|
||||
else:
|
||||
|
||||
try:
|
||||
@@ -259,6 +264,9 @@ class StockLocationList(ListCreateAPI):
|
||||
# All sub-locations to be returned too?
|
||||
if cascade:
|
||||
parents = location.get_descendants(include_self=True)
|
||||
if depth is not None:
|
||||
parents = parents.filter(level__lte=location.level + depth)
|
||||
|
||||
parent_ids = [p.id for p in parents]
|
||||
queryset = queryset.filter(parent__in=parent_ids)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user