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:
@@ -364,7 +364,7 @@ class AdGengHuanDaShou(APIView):
|
||||
|
||||
# 8. 验证新打手ID是否存在,并且是打手身份
|
||||
try:
|
||||
new_dashou_user = User.query.get(
|
||||
new_dashou_user = User.query.select_related('DashouProfile').get(
|
||||
UserUID=new_dashou_id,
|
||||
#user_type='PlayerID'
|
||||
)
|
||||
@@ -459,7 +459,7 @@ class AdGengHuanDaShou(APIView):
|
||||
if old_dashou_id:
|
||||
try:
|
||||
# 查询原打手主表
|
||||
old_dashou_user = User.query.get(
|
||||
old_dashou_user = User.query.select_related('DashouProfile').get(
|
||||
UserUID=old_dashou_id,
|
||||
#user_type='PlayerID'
|
||||
)
|
||||
@@ -567,7 +567,7 @@ class AdQiangZhiJieDan(APIView):
|
||||
|
||||
# 6. 查询订单主表
|
||||
try:
|
||||
dingdan_obj = Order.query.get(OrderID=dingdan_id)
|
||||
dingdan_obj = Order.query.select_related('shangjia_kuozhan', 'pingtai_kuozhan').get(OrderID=dingdan_id)
|
||||
except Order.DoesNotExist:
|
||||
return Response(
|
||||
{'code': 404, 'message': '订单不存在', 'data': None},
|
||||
@@ -603,7 +603,7 @@ class AdQiangZhiJieDan(APIView):
|
||||
if jiedan_dashou_id:
|
||||
try:
|
||||
# 查询打手用户主表
|
||||
dashou_user = User.query.get(
|
||||
dashou_user = User.query.select_related('DashouProfile').get(
|
||||
UserUID=jiedan_dashou_id,
|
||||
#user_type='PlayerID'
|
||||
)
|
||||
@@ -646,7 +646,7 @@ class AdQiangZhiJieDan(APIView):
|
||||
|
||||
if shangjia_id:
|
||||
# 查询商家用户主表
|
||||
shangjia_user = User.query.get(
|
||||
shangjia_user = User.query.select_related('ShopProfile').get(
|
||||
UserUID=shangjia_id,
|
||||
#user_type='shop'
|
||||
)
|
||||
@@ -750,7 +750,7 @@ class AdJuJueTuiKuan(APIView):
|
||||
|
||||
# 6. 查询订单主表
|
||||
try:
|
||||
dingdan_obj = Order.query.get(OrderID=dingdan_id)
|
||||
dingdan_obj = Order.query.select_related('shangjia_kuozhan', 'pingtai_kuozhan').get(OrderID=dingdan_id)
|
||||
except Order.DoesNotExist:
|
||||
return Response(
|
||||
{'code': 404, 'message': '订单不存在', 'data': None},
|
||||
@@ -779,7 +779,7 @@ class AdJuJueTuiKuan(APIView):
|
||||
if jiedan_dashou_id:
|
||||
try:
|
||||
# 查询打手用户主表
|
||||
dashou_user = User.query.get(
|
||||
dashou_user = User.query.select_related('DashouProfile').get(
|
||||
UserUID=jiedan_dashou_id,
|
||||
#user_type='PlayerID'
|
||||
)
|
||||
@@ -822,7 +822,7 @@ class AdJuJueTuiKuan(APIView):
|
||||
|
||||
if shangjia_id:
|
||||
# 查询商家用户主表
|
||||
shangjia_user = User.query.get(
|
||||
shangjia_user = User.query.select_related('ShopProfile').get(
|
||||
UserUID=shangjia_id,
|
||||
#user_type='shop'
|
||||
)
|
||||
@@ -958,7 +958,7 @@ class AdTongYiTuiKuanShangJia(APIView):
|
||||
|
||||
# 7. 查询订单主表
|
||||
try:
|
||||
dingdan_obj = Order.query.get(OrderID=dingdan_id)
|
||||
dingdan_obj = Order.query.select_related('shangjia_kuozhan', 'pingtai_kuozhan').get(OrderID=dingdan_id)
|
||||
except Order.DoesNotExist:
|
||||
return Response(
|
||||
{'code': 404, 'message': '订单不存在', 'data': None},
|
||||
@@ -1010,7 +1010,7 @@ class AdTongYiTuiKuanShangJia(APIView):
|
||||
if jiedan_dashou_id:
|
||||
try:
|
||||
# 查询打手用户主表
|
||||
dashou_user = User.query.get(
|
||||
dashou_user = User.query.select_related('DashouProfile').get(
|
||||
UserUID=jiedan_dashou_id,
|
||||
#user_type='PlayerID'
|
||||
)
|
||||
@@ -1035,10 +1035,10 @@ class AdTongYiTuiKuanShangJia(APIView):
|
||||
if shangjia_id:
|
||||
try:
|
||||
# 查询商家用户主表
|
||||
shangjia_user = User.query.get(
|
||||
UserUID=shangjia_id,
|
||||
#user_type='shop'
|
||||
)
|
||||
shangjia_user = User.query.select_related('ShopProfile').get(
|
||||
UserUID=shangjia_id,
|
||||
#user_type='shop'
|
||||
)
|
||||
|
||||
# 获取商家扩展表
|
||||
shangjia_profile = shangjia_user.ShopProfile
|
||||
@@ -1228,7 +1228,7 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
# 14. 更新打手扩展表
|
||||
if jiedan_dashou_id:
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
|
||||
dashou_user = User.query.select_related('DashouProfile').get(UserUID=jiedan_dashou_id)
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
dashou_profile.zhuangtai = 1 # 打手状态设为空闲
|
||||
dashou_profile.tuikuanliang += 1
|
||||
@@ -1239,7 +1239,7 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
# 15. 更新老板扩展表
|
||||
if laoban_id:
|
||||
try:
|
||||
laoban_user = User.query.get(UserUID=laoban_id)
|
||||
laoban_user = User.query.select_related('BossProfile').get(UserUID=laoban_id)
|
||||
laoban_profile = laoban_user.BossProfile
|
||||
laoban_profile.alltui += 1
|
||||
laoban_profile.zonge -= jine
|
||||
@@ -1463,7 +1463,7 @@ class AdJuJueJieSuan(APIView):
|
||||
|
||||
# 8. 更新打手扩展表
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
|
||||
dashou_user = User.query.select_related('DashouProfile').get(UserUID=jiedan_dashou_id)
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
dashou_profile.zhuangtai = 1 # 打手状态设为正常
|
||||
dashou_profile.tuikuanliang += 1 # 退款订单总量+1
|
||||
@@ -1545,7 +1545,7 @@ class AdZhuanYiDaTing(APIView):
|
||||
# 如果有接单打手,更新其扩展表
|
||||
if jiedan_dashou_id:
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
|
||||
dashou_user = User.query.select_related('DashouProfile').get(UserUID=jiedan_dashou_id)
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
dashou_profile.zhuangtai = 1
|
||||
dashou_profile.tuikuanliang += 1
|
||||
@@ -1835,7 +1835,7 @@ class ZxsjghdsView(APIView):
|
||||
# 6.2 释放打手
|
||||
if dashou_id:
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=dashou_id)
|
||||
dashou_user = User.query.select_related('DashouProfile').get(UserUID=dashou_id)
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
dashou_profile.tuikuanliang = (dashou_profile.tuikuanliang or 0) + 1
|
||||
dashou_profile.zhuangtai = 1 # 空闲
|
||||
|
||||
Reference in New Issue
Block a user