perf: use channel index order and avoid redundant metric grouping
This commit is contained in:
@@ -262,6 +262,37 @@ func TestMySQLLaterRegistrationIndexesPreserveMalformedLegacyTimes(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMySQLChannelOwnPlayerSortUsesGroupedCoveringIndex(t *testing.T) {
|
||||
db := openRehearsalMySQL(t)
|
||||
for _, sql := range []string{
|
||||
"CREATE TABLE tab_promote(id BIGINT,source_db VARCHAR(10),create_time BIGINT,PRIMARY KEY(id,source_db))",
|
||||
"CREATE TABLE tab_user(id BIGINT,source_db VARCHAR(10),promote_id BIGINT,puid BIGINT,sw_register_time_unix BIGINT,idcard VARCHAR(20),PRIMARY KEY(id,source_db),INDEX idx_alert_user_window(source_db,promote_id,sw_register_time_unix,puid))",
|
||||
"INSERT INTO tab_promote VALUES(1,'lx',1),(2,'lx',2),(1,'hw',3)",
|
||||
"INSERT INTO tab_user VALUES(1,'lx',1,0,1,'a'),(2,'lx',1,0,1,'a'),(3,'lx',2,0,1,'b'),(1,'hw',1,0,1,'c')",
|
||||
} {
|
||||
if err := db.Exec(sql).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
keys, err := channelMetricPage(db, db.Table("tab_promote p").Where("p.source_db='lx'"), business.ChannelFilter{Sources: []string{"lx"}, SortField: "playerCount"}, business.NewListOptions(business.ListLimit(1)))
|
||||
if err != nil || len(keys) != 1 || keys[0] != (business.ChannelKey{SourceDB: "lx", ID: 1}) {
|
||||
t.Fatalf("own-channel sort: %v %v", keys, err)
|
||||
}
|
||||
var counts []struct {
|
||||
SourceDB string
|
||||
PromoteID uint64
|
||||
Count int64
|
||||
}
|
||||
if err := whereMetricChannels(db, []business.ChannelKey{{SourceDB: "lx", ID: 2}, {SourceDB: "hw", ID: 1}}).Table("tab_user").Select("source_db,promote_id,COUNT(*) AS count").Group("source_db,promote_id").Scan(&counts).Error; err != nil || len(counts) != 2 {
|
||||
t.Fatalf("paired source filter: %v %v", counts, err)
|
||||
}
|
||||
for _, row := range counts {
|
||||
if row.Count != 1 {
|
||||
t.Fatalf("included a same-id channel from another platform: %+v", row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMySQLChannelCreationSerializesAccount(t *testing.T) {
|
||||
db := openRehearsalMySQL(t)
|
||||
if err := db.AutoMigrate(&platformChannelPO{}, &channelSettlementPO{}); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user