From 7e3fc11bf555a254c7a4bde9e58dcc44ea8ac466 Mon Sep 17 00:00:00 2001 From: yueli Date: Fri, 4 Sep 2026 15:16:20 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20warehouse/tree=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8A=A0=203=20=E9=98=B6=E6=AE=B5=E8=80=97=E6=97=B6=E6=89=93?= =?UTF-8?q?=E7=82=B9=E6=97=A5=E5=BF=97=EF=BC=88=E6=9F=A5=E5=BA=93/build=5F?= =?UTF-8?q?tree/=E5=BA=8F=E5=88=97=E5=8C=96=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-backend/app/api/v1/warehouse.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/inventory-backend/app/api/v1/warehouse.py b/inventory-backend/app/api/v1/warehouse.py index 53d5fe8..9208e95 100644 --- a/inventory-backend/app/api/v1/warehouse.py +++ b/inventory-backend/app/api/v1/warehouse.py @@ -36,19 +36,33 @@ def get_tree(): """ 获取库位树形结构 """ + import time + from flask import current_app + t0 = time.time() try: # 查询所有库位,按 name 升序排序 all_locations = SysWarehouseLocation.query.order_by(SysWarehouseLocation.name.asc()).all() + t1 = time.time() # 构建树形结构 tree_data = build_tree(all_locations, parent_id=None) - - return jsonify({ + t2 = time.time() + + resp = jsonify({ 'code': 200, 'msg': 'success', 'data': tree_data }) + t3 = time.time() + + print( + f"[warehouse/tree 打点] 阶段1-查库={t1 - t0:.3f}s | 阶段2-build_tree+to_dict={t2 - t1:.3f}s | " + f"阶段3-jsonify序列化={t3 - t2:.3f}s | 总={t3 - t0:.3f}s (rows={len(all_locations)}, tree_top={len(tree_data)})", + flush=True + ) + return resp except Exception as e: + print(f"[warehouse/tree 打点] 异常: {e}", flush=True) return jsonify({ 'code': 500, 'msg': str(e),