fix: 消除游戏下拉重复请求并优化申请范围查询
This commit is contained in:
@@ -1,12 +1,49 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"kra/internal/biz/business"
|
||||
)
|
||||
|
||||
func TestMySQLApprovedGameIndexSupportsExistenceLookup(t *testing.T) {
|
||||
db := openRehearsalMySQL(t)
|
||||
for _, sql := range []string{
|
||||
"CREATE TABLE tab_game(id INT,source_db VARCHAR(10),game_name VARCHAR(64),PRIMARY KEY(id,source_db),KEY(game_name)) ENGINE=InnoDB",
|
||||
"CREATE TABLE tab_promote(id INT,source_db VARCHAR(10),PRIMARY KEY(id,source_db)) ENGINE=InnoDB",
|
||||
"CREATE TABLE tab_promote_apply(id INT PRIMARY KEY,source_db VARCHAR(10),game_id INT,promote_id INT,status INT,payload VARCHAR(500)) ENGINE=InnoDB",
|
||||
"INSERT INTO tab_game VALUES(1,'lx','游戏甲'),(1,'hw','无申请同号游戏')",
|
||||
"INSERT INTO tab_promote VALUES(100,'lx')",
|
||||
"INSERT INTO tab_promote_apply VALUES(1,'lx',1,100,1,'keep'),(2,'lx',1,100,0,'pending')",
|
||||
} {
|
||||
if err := db.Exec(sql).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for attempt := 0; attempt < 2; attempt++ {
|
||||
if err := migrateApprovedGameIndexes(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var columns []string
|
||||
if err := db.Raw("SELECT column_name FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name='tab_promote_apply' AND index_name='idx_sw_apply_game_scope' ORDER BY seq_in_index").Scan(&columns).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Join(columns, ",") != "game_id,source_db,status,promote_id" {
|
||||
t.Fatal("申请查询需要覆盖完整游戏、平台、状态和渠道条件")
|
||||
}
|
||||
rows, err := NewLedgerRepo(testData{db}).Games(context.Background(), business.UserScope{All: true}, nil, "", 50)
|
||||
if err != nil || len(rows) != 1 || rows[0].SourceDB != "lx" {
|
||||
t.Fatalf("索引不能改变游戏可见范围: %+v %v", rows, err)
|
||||
}
|
||||
var payload string
|
||||
if err := db.Raw("SELECT payload FROM tab_promote_apply WHERE id=1").Scan(&payload).Error; err != nil || payload != "keep" {
|
||||
t.Fatal("索引迁移不能修改申请数据")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMySQLBusinessQueryIndexesAreAdditiveAndIdempotent(t *testing.T) {
|
||||
db := openRehearsalMySQL(t)
|
||||
definitions := map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user