perf: exclude inactive catalog rows from report summary lookups

This commit is contained in:
Yvan
2026-11-06 02:45:47 +08:00
parent 013795041b
commit 75a2904a14
2 changed files with 40 additions and 3 deletions
+12 -3
View File
@@ -228,6 +228,13 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
}
}
if metricFilter {
// Only channels present in the report can contribute to its summary.
// Keep zero-activity catalog rows out of the aggregate IN list; large
// catalogs would otherwise exhaust MySQL's prepared-statement parameters.
factKeys := make([]business.AnalyticsKey, 0, len(rowMap))
for key := range rowMap {
factKeys = append(factKeys, key)
}
if f.IncludesInactiveRows() {
if err := includeInactiveAnalyticsRows(db, scope, f, rowMap); err != nil {
return nil, err
@@ -243,9 +250,11 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
}
}
if withGlobal {
keys := make([]business.AnalyticsKey, 0, len(rowMap))
for key := range rowMap {
keys = append(keys, key)
keys := make([]business.AnalyticsKey, 0, len(factKeys))
for _, key := range factKeys {
if rowMap[key] != nil {
keys = append(keys, key)
}
}
// Deduplicate identities across all matched channels, before pagination.
// Summing per-channel counts would double-count shared players.