chore: warehouse/tree 接口加 3 阶段耗时打点日志(查库/build_tree/序列化)
This commit is contained in:
@ -36,19 +36,33 @@ def get_tree():
|
|||||||
"""
|
"""
|
||||||
获取库位树形结构
|
获取库位树形结构
|
||||||
"""
|
"""
|
||||||
|
import time
|
||||||
|
from flask import current_app
|
||||||
|
t0 = time.time()
|
||||||
try:
|
try:
|
||||||
# 查询所有库位,按 name 升序排序
|
# 查询所有库位,按 name 升序排序
|
||||||
all_locations = SysWarehouseLocation.query.order_by(SysWarehouseLocation.name.asc()).all()
|
all_locations = SysWarehouseLocation.query.order_by(SysWarehouseLocation.name.asc()).all()
|
||||||
|
t1 = time.time()
|
||||||
|
|
||||||
# 构建树形结构
|
# 构建树形结构
|
||||||
tree_data = build_tree(all_locations, parent_id=None)
|
tree_data = build_tree(all_locations, parent_id=None)
|
||||||
|
t2 = time.time()
|
||||||
|
|
||||||
return jsonify({
|
resp = jsonify({
|
||||||
'code': 200,
|
'code': 200,
|
||||||
'msg': 'success',
|
'msg': 'success',
|
||||||
'data': tree_data
|
'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:
|
except Exception as e:
|
||||||
|
print(f"[warehouse/tree 打点] 异常: {e}", flush=True)
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'code': 500,
|
'code': 500,
|
||||||
'msg': str(e),
|
'msg': str(e),
|
||||||
|
|||||||
Reference in New Issue
Block a user