perf: 优化商务统计的渠道权限子查询

This commit is contained in:
Yvan
2026-11-04 16:57:14 +08:00
parent 2efce4d821
commit 19926d275c
2 changed files with 4 additions and 1 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ func analyticsQuery(db *gorm.DB, scope business.AnalyticsScope, f business.Analy
if scope.Viewer.All && scope.IncludeSub && f.PromoteType == nil && f.PromoteName == "" {
return q
}
return q.Where("EXISTS (?)", analyticsPromotes(db, scope, f, "p").Select("1").Where("p.source_db=r.source_db AND p.id=r.promote_id"))
// 保留完整的可见渠道筛选,用成对 IN 让 MySQL 5.7 将报表与权限
// 查询转换为半连接,避免为每条身份记录重新执行相关渠道子查询。
return q.Where("(r.source_db,r.promote_id) IN (?)", analyticsPromotes(db, scope, f, "p").Select("p.source_db,p.id"))
}
type analyticsAggPO struct {