perf: P1 性能优化批量修复 + kefu 视图拆分
P1 性能优化(避免循环内 N+1 / N 次 DB 查询): - shop_order_views._batch_images: 移除 ThreadPoolExecutor 掩盖的 N 次查询,改单次批量 + Python 侧分组 - product_query.DashouHuiyuanList: 5N 查询 -> 3 次批量预取 + 本地闭包判断 - roles.GetRolePermissionView / 用户列表: 循环内 RolePermission/Permission/UserRole/Role -> 批量 __in 预取 - guanli / zuzhang 杜次分红 4.2/4.3: 循环内 update_or_create + 单条 delete -> bulk_create + bulk_update + 批量 delete - admin_config QQ 群配置: 循环内 exists/first/save/create -> 批量预取 + bulk_create + bulk_update - jituan 服务层多处合并统计查询、批量预取 map - rank 多处循环 N+1 改批量预取 - backend 多处循环内 count/create 改批量 - config/orders/merchant_ops 多处循环 N+1 改批量预取 其他改动: - users/views/kefu.py 拆分为 kefu_base/kefu_dashou/kefu_orders/kefu_punishment/kefu_withdraw 5 个文件 - 删除遗留脚本 check_prod_uid.py / create_rbac_tables.sql
This commit is contained in:
@@ -204,7 +204,9 @@ class WechatPayNotifyView(APIView):
|
||||
|
||||
# 锁定订单防止并发
|
||||
try:
|
||||
dingdan = Order.query.select_for_update().filter(OrderID=out_trade_no).first()
|
||||
dingdan = Order.query.select_for_update().select_related(
|
||||
'pingtai_kuozhan', 'shangjia_kuozhan'
|
||||
).filter(OrderID=out_trade_no).first()
|
||||
except Exception as e:
|
||||
logger.error(f"查询订单异常: {e}")
|
||||
raise
|
||||
@@ -263,7 +265,7 @@ class WechatPayNotifyView(APIView):
|
||||
if hasattr(dingdan, 'pingtai_kuozhan'):
|
||||
laoban_id = dingdan.pingtai_kuozhan.BossID
|
||||
if laoban_id:
|
||||
user_main = User.query.filter(UserUID=laoban_id).first()
|
||||
user_main = User.query.filter(UserUID=laoban_id).select_related('BossProfile').first()
|
||||
if user_main and hasattr(user_main, 'BossProfile'):
|
||||
boss = user_main.BossProfile
|
||||
boss.zonge = (boss.zonge or 0) + (dingdan.Amount or 0)
|
||||
@@ -537,7 +539,7 @@ class PaymentVerifyView(APIView):
|
||||
# 更新老板扩展表
|
||||
laoban_id = dingdan.pingtai_kuozhan.BossID if hasattr(dingdan, 'pingtai_kuozhan') else None
|
||||
if laoban_id:
|
||||
user_main = User.query.filter(UserUID=laoban_id).first()
|
||||
user_main = User.query.filter(UserUID=laoban_id).select_related('BossProfile').first()
|
||||
if user_main and hasattr(user_main, 'BossProfile'):
|
||||
boss = user_main.BossProfile
|
||||
boss.zonge = (boss.zonge or 0) + (dingdan.Amount or 0)
|
||||
@@ -709,13 +711,16 @@ class CreateOrderView(APIView):
|
||||
zhiding_user = User.query.filter(
|
||||
UserUID=zhiding,
|
||||
#user_type='PlayerID'
|
||||
).first()
|
||||
).select_related('DashouProfile').first()
|
||||
|
||||
if not zhiding_user:
|
||||
return Response({'code': 7, 'msg': '指定打手不存在', 'data': None})
|
||||
|
||||
# 查询打手扩展表
|
||||
dashou_profile = UserDashou.query.filter(user=zhiding_user).first()
|
||||
try:
|
||||
dashou_profile = zhiding_user.DashouProfile
|
||||
except UserDashou.DoesNotExist:
|
||||
dashou_profile = None
|
||||
|
||||
if not dashou_profile:
|
||||
return Response({'code': 8, 'msg': '指定用户不存在或已封禁', 'data': None})
|
||||
|
||||
Reference in New Issue
Block a user