perf: 减少统计页面资料读取并优化区服选项查询

This commit is contained in:
Yvan
2026-11-04 16:42:11 +08:00
parent 503f3b1a7d
commit 2efce4d821
8 changed files with 184 additions and 13 deletions
+5 -1
View File
@@ -155,7 +155,11 @@ func (r *serverAnalysisRepo) Servers(ctx context.Context, sources, games []strin
return nil, business.ErrServerOptionsUnavailable
}
}
q := db.Table("tab_game_server s").Where("EXISTS (?)", db.Table("tab_game g").Select("1").Where("g.source_db=s.source_db AND g.id=s.game_id AND g.game_name IN ?", games))
// MySQL 5.7 不会将相关 EXISTS 展开为半连接,导致扫描全部区服。
// 多列 IN 让优化器先按游戏名索引定位,再使用区服的 game_id 索引,
// 同时保留平台匹配和重复游戏资料不扩增结果的语义。
gamesQuery := db.Table("tab_game g").Select("g.source_db,g.id").Where("g.game_name IN ?", games)
q := db.Table("tab_game_server s").Where("(s.source_db,s.game_id) IN (?)", gamesQuery)
if len(sources) > 0 {
q = q.Where("s.source_db IN ?", sources)
}