From 7998a65ae0120c1a1102e3416a478882e0d2d279 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 28 Aug 2023 17:24:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=A4=E7=BB=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron/group_cron/group_list.go | 4 ++-- domain/model/group_m/mic.go | 34 ++++++++++++++++++++++++++++++++++ route/group_r/group_list.go | 6 +++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cron/group_cron/group_list.go b/cron/group_cron/group_list.go index d35947c..e3574f4 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 20ba960..3dce551 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 e4dd222..3d36459 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 } -- 2.22.0