From ee20692e952c66dd384b10cd05c7167dcd743f39 Mon Sep 17 00:00:00 2001 From: Yvan <8574526@qq,com> Date: Thu, 5 Nov 2026 09:26:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8C=BA=E6=9C=8D=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=89=B9=E9=87=8F=E6=B8=B8=E6=88=8F=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/business/analytics.go | 15 +++------------ internal/data/business/approved_games.go | 19 +++++++++++++++++++ internal/data/business/server_analysis.go | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/internal/data/business/analytics.go b/internal/data/business/analytics.go index 88a135b..b1bd6c3 100644 --- a/internal/data/business/analytics.go +++ b/internal/data/business/analytics.go @@ -291,18 +291,9 @@ func filterAnalyticsGames(db *gorm.DB, scope business.AnalyticsScope, f business for key := range rows { keys = append(keys, key) } - allowed := map[business.AnalyticsKey]bool{} - for start := 0; start < len(keys); start += 300 { - var games []analyticsAggPO - q := approvedGamesQuery(db, scope.Viewer, f.Sources).Where("(g.source_db,g.id) IN ?", analyticsPairs(keys[start:min(start+300, len(keys))])) - if err := q.Select("g.source_db,g.id AS entity_id").Scan(&games).Error; err != nil { - return business.ErrStorage - } - for _, game := range games { - if game.ID != nil { - allowed[business.AnalyticsKey{SourceDB: game.SourceDB, ID: *game.ID}] = true - } - } + allowed, err := approvedGameKeys(db, scope.Viewer, f.Sources, keys) + if err != nil { + return err } for key := range rows { if !allowed[key] { diff --git a/internal/data/business/approved_games.go b/internal/data/business/approved_games.go index 78efe92..f8cbb5e 100644 --- a/internal/data/business/approved_games.go +++ b/internal/data/business/approved_games.go @@ -29,6 +29,25 @@ func approvedGamesQuery(db *gorm.DB, viewer business.UserScope, sources []string return q } +// Check authorization for the distinct games present in an aggregated report. +func approvedGameKeys(db *gorm.DB, viewer business.UserScope, sources []string, keys []business.AnalyticsKey) (map[business.AnalyticsKey]bool, error) { + allowed := map[business.AnalyticsKey]bool{} + for start := 0; start < len(keys); start += 300 { + var games []struct { + SourceDB string `gorm:"column:source_db"` + ID int64 + } + q := approvedGamesQuery(db, viewer, sources).Where("(g.source_db,g.id) IN ?", analyticsPairs(keys[start:min(start+300, len(keys))])) + if err := q.Select("g.source_db,g.id").Scan(&games).Error; err != nil { + return nil, business.ErrStorage + } + for _, game := range games { + allowed[business.AnalyticsKey{SourceDB: game.SourceDB, ID: game.ID}] = true + } + } + return allowed, nil +} + func migrateApprovedGameIndexes(db *gorm.DB) error { return migrateQueryIndexes(db, []businessQueryIndex{ {"tab_promote_apply", "idx_sw_apply_game_scope", []string{"game_id", "source_db", "status", "promote_id"}}, diff --git a/internal/data/business/server_analysis.go b/internal/data/business/server_analysis.go index 12eab75..d1d085b 100644 --- a/internal/data/business/server_analysis.go +++ b/internal/data/business/server_analysis.go @@ -17,7 +17,6 @@ func NewServerAnalysisRepo(data Provider) business.ServerAnalysisRepo { func serverReportQuery(db *gorm.DB, scope business.AnalyticsScope, f business.ServerAnalysisFilter, table string, mode int) *gorm.DB { q := ledgerScopeQuery(db, business.LedgerScope{Viewer: scope.Viewer, IncludeSub: scope.IncludeSub, Unrestricted: scope.Viewer.All}, business.LedgerFilter{Sources: f.Sources}, table) q = q.Where("r.stat_date >= ? AND r.stat_date <= ? AND r.dedup_mode=? AND r.server_num != ''", f.Begin, f.End, mode).Where("r.game_name IN ?", f.GameNames) - q = q.Where("(r.source_db,r.game_id) IN (?)", approvedGamesQuery(db, scope.Viewer, f.Sources).Select("g.source_db,g.id")) if f.ServerNum != "" { q = q.Where("r.server_num=?", f.ServerNum) } @@ -88,6 +87,23 @@ func (r *serverAnalysisRepo) Aggregate(ctx context.Context, scope business.Analy row.Pay = po.Amount row.GameName = strings.TrimSpace(po.GameName) } + gameSet := map[business.AnalyticsKey]bool{} + for key := range rows { + gameSet[business.AnalyticsKey{SourceDB: key.SourceDB, ID: key.GameID}] = true + } + gameKeys := make([]business.AnalyticsKey, 0, len(gameSet)) + for key := range gameSet { + gameKeys = append(gameKeys, key) + } + allowed, err := approvedGameKeys(db, scope.Viewer, f.Sources, gameKeys) + if err != nil { + return nil, err + } + for key := range rows { + if !allowed[business.AnalyticsKey{SourceDB: key.SourceDB, ID: key.GameID}] { + delete(rows, key) + } + } if err := fillServerAnalysisNames(db, rows); err != nil { return nil, err }