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),