perf: 优化商务统计的渠道权限子查询
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user