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:
2026-07-05 23:17:38 +08:00
parent 76ea5f8255
commit f1c8633345
54 changed files with 5332 additions and 4494 deletions

View File

@@ -422,11 +422,14 @@ class JiedanView(APIView):
# 7. 更新打手扩展表如果有打手ID和分成
if jiedan_dashou_id and dashou_fencheng > 0:
# 查询打手用户
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).first()
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).select_related('DashouProfile').first()
if dashou_user:
# 查询打手扩展表
dashou_kuozhan = UserDashou.query.filter(user=dashou_user).first()
try:
dashou_kuozhan = dashou_user.DashouProfile
except UserDashou.DoesNotExist:
dashou_kuozhan = None
if dashou_kuozhan:
# 更新四个金额字段
@@ -585,7 +588,7 @@ class DingdanXiangqingView2(APIView):
jiedan_time = ''
tijiao_time = ''
if jiedan_dashou_id:
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).first()
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).select_related('DashouProfile').first()
if dashou_user:
dashou_touxiang = dashou_user.Avatar or ''
try:
@@ -734,7 +737,7 @@ class JiedanView2(APIView):
# 9. 更新打手收益与状态
if jiedan_dashou_id and dashou_fencheng > 0:
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).first()
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).select_related('DashouProfile').first()
if dashou_user:
try:
dashou_ext = dashou_user.DashouProfile