diff --git a/inventory-backend/app/api/v1/warehouse.py b/inventory-backend/app/api/v1/warehouse.py index 9208e95..51718fa 100644 --- a/inventory-backend/app/api/v1/warehouse.py +++ b/inventory-backend/app/api/v1/warehouse.py @@ -36,33 +36,19 @@ 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() - # 构建树形结构 + # 构建树形结构(O(N) 内存组装,见 build_tree) tree_data = build_tree(all_locations, parent_id=None) - t2 = time.time() - resp = jsonify({ + return 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),