fix: remove unused channel activity filters

This commit is contained in:
Yvan
2026-11-05 14:51:51 +08:00
parent dd02620b5e
commit 56874b33da
7 changed files with 14 additions and 72 deletions
+3 -32
View File
@@ -2,7 +2,6 @@ package business
import (
"context"
"math/big"
"sort"
"strings"
"time"
@@ -172,7 +171,6 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
var global []portraitCountPO
globalPay := "0"
withGlobal := kind == business.ChannelAnalytics && scope.Viewer.All
metricFiltered := kind == business.ChannelAnalytics && (f.HasRegister != nil || f.HasPay != nil)
group, queryContext := errgroup.WithContext(ctx)
// 每个请求最多两个并行查询,复用同一存储客户端;结果读取完后再组装 DO。
group.SetLimit(2)
@@ -191,7 +189,7 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
}
return nil
})
if withGlobal && !metricFiltered {
if withGlobal {
group.Go(func() error {
q := analyticsQuery(queryDB, scope, f, "tab_sw_report_day_key", mode)
if err := q.Select("r.metric,COUNT(DISTINCT " + portraitIdentity(queryDB, scope.IDCardDedup) + ") AS count").Group("r.metric").Scan(&global).Error; err != nil {
@@ -216,8 +214,8 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
putAnalyticsCount(&rowFor(po).Counts, po.Metric, po.Count)
}
}
// Report rows come from facts in the selected period. Registration/payment
// filters narrow that same set; they must not add the entire channel catalog.
// Report rows come from facts in the selected period. Looking up channel
// metadata must not expand them into the entire channel catalog.
if kind == business.ChannelAnalytics && !scope.Viewer.All {
if err := filterAnalyticsRows(db, scope, f, rowMap); err != nil {
return nil, err
@@ -228,33 +226,6 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
return nil, err
}
}
if metricFiltered {
for key, row := range rowMap {
pay, ok := new(big.Rat).SetString(row.Pay)
if !ok {
return nil, business.ErrStorage
}
if f.HasRegister != nil && (row.Counts.Register > 0) != *f.HasRegister || f.HasPay != nil && (pay.Sign() > 0) != *f.HasPay {
delete(rowMap, key)
}
}
// Recompute the administrator's distinct-player totals over matched
// channel trees, before pagination. Summing per-row ratios is incorrect.
if withGlobal && len(rowMap) > 0 {
keys := make([]business.AnalyticsKey, 0, len(rowMap))
for key := range rowMap {
keys = append(keys, key)
}
q, id := analyticsRoot(db, kind, scope, f, "tab_sw_report_day_key", mode, false)
if err := q.Where("(r.source_db,"+id+") IN ?", analyticsPairs(keys)).Select("r.metric,COUNT(DISTINCT " + portraitIdentity(db, scope.IDCardDedup) + ") AS count").Group("r.metric").Scan(&global).Error; err != nil {
return nil, business.ErrStorage
}
q, id = analyticsRoot(db, kind, scope, f, "tab_sw_report_day", 0, true)
if err := q.Where("(r.source_db,"+id+") IN ?", analyticsPairs(keys)).Select("COALESCE(SUM(r.total_pay),0)").Scan(&globalPay).Error; err != nil {
return nil, business.ErrStorage
}
}
}
if withGlobal {
totals := toPortraitCounts(global)
result.GlobalCounts, result.GlobalPay = &totals, globalPay