diff --git a/cron/group_cron/group_list.go b/cron/group_cron/group_list.go index d35947c75111ad8ce6d39b3f2c96744fe684f76e..e3574f49c81fb7ceaeb2a3610168e8bb4a375513 100644 --- a/cron/group_cron/group_list.go +++ b/cron/group_cron/group_list.go @@ -10,7 +10,7 @@ import ( func GroupCountryListSort() { // 常用国家-每15分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口 - spec := "0 */15 * * * ?" + spec := "0 */2 * * * ?" c := cron.New() _ = c.AddFunc(spec, func() { var model = domain.CreateModelNil() @@ -18,7 +18,7 @@ func GroupCountryListSort() { }) // 非常用国家-每60分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口 - spec2 := "0 15 * * * ?" + spec2 := "0 28 * * * ?" _ = c.AddFunc(spec2, func() { var model = domain.CreateModelNil() group_s.SortGroupNotCommonCountryList(model) diff --git a/domain/model/group_m/mic.go b/domain/model/group_m/mic.go index 20ba9607713c6bda669bbc9feba19e359ce0290e..3dce551a1125e6839a7a71460cd3ac4c48080a8a 100644 --- a/domain/model/group_m/mic.go +++ b/domain/model/group_m/mic.go @@ -920,6 +920,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) { return resultGroupUuids, nil } +// 获取麦上人数 +func GetMicHasInGroupNumByList(model *domain.Model, groupIds []string) (map[string]int64, error) { + resultGroupUuids := make(map[string]int64, len(groupIds)) + micHasInKey := redis_key.GetPrefixGroupMicHasIn() + for _, group := range groupIds { + isMem, err := redisCli.GetRedis().SIsMember(context.Background(), micHasInKey, group).Result() + if err != nil { + model.Log.Errorf("GetMicHasInGroupNumByList err:%v", err) + return nil, myerr.WrapErr(err) + } + if isMem { + s := strings.Replace(micHasInScript, "{key}", micHasInKey, -1) + s = strings.Replace(s, "{remKey}", group, -1) + for i := 1; i <= MaxMicNum; i++ { + s = strings.Replace(s, "{key"+strconv.Itoa(i)+"}", redis_key.GetPrefixGroupMicUser(group, i), -1) + } + //r, err := redis2.NewScript(s).Run(context.Background(), redisCli.GetRedis(), []string{}).Result() + sha1, err := model.Redis.ScriptLoad(model, s).Result() + if err != nil { + return nil, myerr.WrapErr(err) + } + micNum, err := model.Redis.EvalSha(model, sha1, nil, nil).Int64() + if err != nil { + return nil, myerr.WrapErr(err) + } + //d := r.(int64) + if micNum > 0 { + resultGroupUuids[group] = micNum + } + } + } + return resultGroupUuids, nil +} + //获取麦上有人的群组&&麦上的数(有时间性,目前是24小时) func GetMicHasInPeriodGroupUser() (map[string][]uint64, error) { //清理超过12小时的 diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index e4dd222b05c66065736f88d309cdbff3389fa20d..3d364590c201481b82d06d63688cde816fe13907 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -1564,6 +1564,11 @@ func GetGroupByCountryV2(c *gin.Context) (*mycontext.MyContext, error) { model.Log.Errorf("GetGroupByCountry err:%v", err) return myContext, err } + // 获取麦上人数 + micGroupNum, err := group_m.GetMicHasInGroupNum(model) + if err != nil { + return myContext, err + } for _, i := range hotGroupList { var maxStage *uint16 = nil @@ -1630,7 +1635,6 @@ func GetGroupByCountryV2(c *gin.Context) (*mycontext.MyContext, error) { }) } - model.Log.Infof("GetGroupByCountry cost6:%v", time.Now().Sub(beginTime)) resp.ResponsePageOk(c, result, uint(total), pageIndex) return myContext, nil }