模拟飘屏修复
This commit is contained in:
parent
9aecdf34a3
commit
5b92fef113
@ -199,7 +199,7 @@ func (w *BroadcastSimulationWorker) run(ctx context.Context, req ContinuousSimul
|
|||||||
|
|
||||||
func (w *BroadcastSimulationWorker) runOnce(ctx context.Context, req ContinuousSimulationRequest, rng *rand.Rand) {
|
func (w *BroadcastSimulationWorker) runOnce(ctx context.Context, req ContinuousSimulationRequest, rng *rand.Rand) {
|
||||||
regionCode := req.RegionCodes[rng.Intn(len(req.RegionCodes))]
|
regionCode := req.RegionCodes[rng.Intn(len(req.RegionCodes))]
|
||||||
userID, err := w.randomOfflineUser(ctx, req.SysOrigin, regionCode, rng)
|
userID, err := w.randomOfflineUser(ctx, req.SysOrigin, rng)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.setLastError(err)
|
w.setLastError(err)
|
||||||
return
|
return
|
||||||
@ -332,14 +332,12 @@ func (w *BroadcastSimulationWorker) sendContinuous(ctx context.Context, req Broa
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BroadcastSimulationWorker) randomOfflineUser(ctx context.Context, sysOrigin string, regionCode string, rng *rand.Rand) (int64, error) {
|
func (w *BroadcastSimulationWorker) randomOfflineUser(ctx context.Context, sysOrigin string, rng *rand.Rand) (int64, error) {
|
||||||
onlineIDs := w.onlineUserIDs(ctx, sysOrigin)
|
onlineIDs := w.onlineUserIDs(ctx, sysOrigin)
|
||||||
query := w.db.WithContext(ctx).
|
query := w.db.WithContext(ctx).
|
||||||
Table("user_base_info AS user").
|
Table("user_base_info AS user").
|
||||||
Select("user.id AS id").
|
Select("user.id AS id").
|
||||||
Joins("LEFT JOIN voice_room_region_country AS region ON region.sys_origin = ? AND region.country_code = user.country_code AND region.enabled = ?", sysOrigin, true).
|
|
||||||
Where("user.origin_sys = ?", sysOrigin).
|
Where("user.origin_sys = ?", sysOrigin).
|
||||||
Where("(region.region_code = ? OR user.country_code = ?)", regionCode, regionCode).
|
|
||||||
Where("user.id > 0")
|
Where("user.id > 0")
|
||||||
if len(onlineIDs) > 0 && len(onlineIDs) <= 1000 {
|
if len(onlineIDs) > 0 && len(onlineIDs) <= 1000 {
|
||||||
query = query.Where("user.id NOT IN ?", onlineIDs)
|
query = query.Where("user.id NOT IN ?", onlineIDs)
|
||||||
@ -363,7 +361,7 @@ func (w *BroadcastSimulationWorker) randomOfflineUser(ctx context.Context, sysOr
|
|||||||
filtered = append(filtered, user)
|
filtered = append(filtered, user)
|
||||||
}
|
}
|
||||||
if len(filtered) == 0 {
|
if len(filtered) == 0 {
|
||||||
return 0, common.NewAppError(http.StatusNotFound, "simulation_offline_user_not_found", "offline user not found for selected region")
|
return 0, common.NewAppError(http.StatusNotFound, "simulation_offline_user_not_found", "offline user not found")
|
||||||
}
|
}
|
||||||
return filtered[rng.Intn(len(filtered))].ID, nil
|
return filtered[rng.Intn(len(filtered))].ID, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user