fix: 消除游戏下拉重复请求并优化申请范围查询
This commit is contained in:
@@ -19,10 +19,18 @@ func approvedGamesAvailable(db *gorm.DB) (bool, error) {
|
||||
// 用平台和 ID 配对,避免同号游戏或其他商务的申请扩大可选范围。
|
||||
func approvedGamesQuery(db *gorm.DB, viewer business.UserScope, sources []string) *gorm.DB {
|
||||
promotes := ledgerBasePromotes(db, business.LedgerScope{Viewer: viewer, IncludeSub: true, Unrestricted: viewer.All}, business.LedgerFilter{Sources: sources}, "approved_p").Select("approved_p.source_db,approved_p.id")
|
||||
applications := db.Table("tab_promote_apply a").Select("a.source_db,a.game_id").Where("a.status=1").Where("(a.source_db,a.promote_id) IN (?)", promotes)
|
||||
q := db.Table("tab_game g").Where("(g.source_db,g.id) IN (?)", applications)
|
||||
// 逐个游戏检查有效申请,命中即停止;非相关 IN 在 MySQL 5.7 会先
|
||||
// 物化整张百万级申请表,即使下拉只需要前 50 项也要扫描全部申请。
|
||||
applications := db.Table("tab_promote_apply a").Select("1").Where("a.source_db=g.source_db AND a.game_id=g.id AND a.status=1").Where("(a.source_db,a.promote_id) IN (?)", promotes)
|
||||
q := db.Table("tab_game g").Where("EXISTS (?)", applications)
|
||||
if len(sources) > 0 {
|
||||
q = q.Where("g.source_db IN ?", sources)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
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"}},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user