Commit 7998a65a authored by chenweijian's avatar chenweijian

群组优化

parent f34d8846
This commit is part of merge request !73. Comments created here will be created in the context of that merge request.
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
func GroupCountryListSort() { func GroupCountryListSort() {
// 常用国家-每15分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口 // 常用国家-每15分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口
spec := "0 */15 * * * ?" spec := "0 */2 * * * ?"
c := cron.New() c := cron.New()
_ = c.AddFunc(spec, func() { _ = c.AddFunc(spec, func() {
var model = domain.CreateModelNil() var model = domain.CreateModelNil()
...@@ -18,7 +18,7 @@ func GroupCountryListSort() { ...@@ -18,7 +18,7 @@ func GroupCountryListSort() {
}) })
// 非常用国家-每60分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口 // 非常用国家-每60分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口
spec2 := "0 15 * * * ?" spec2 := "0 28 * * * ?"
_ = c.AddFunc(spec2, func() { _ = c.AddFunc(spec2, func() {
var model = domain.CreateModelNil() var model = domain.CreateModelNil()
group_s.SortGroupNotCommonCountryList(model) group_s.SortGroupNotCommonCountryList(model)
......
...@@ -920,6 +920,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) { ...@@ -920,6 +920,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) {
return resultGroupUuids, nil 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小时) //获取麦上有人的群组&&麦上的数(有时间性,目前是24小时)
func GetMicHasInPeriodGroupUser() (map[string][]uint64, error) { func GetMicHasInPeriodGroupUser() (map[string][]uint64, error) {
//清理超过12小时的 //清理超过12小时的
......
...@@ -1564,6 +1564,11 @@ func GetGroupByCountryV2(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1564,6 +1564,11 @@ func GetGroupByCountryV2(c *gin.Context) (*mycontext.MyContext, error) {
model.Log.Errorf("GetGroupByCountry err:%v", err) model.Log.Errorf("GetGroupByCountry err:%v", err)
return myContext, err return myContext, err
} }
// 获取麦上人数
micGroupNum, err := group_m.GetMicHasInGroupNum(model)
if err != nil {
return myContext, err
}
for _, i := range hotGroupList { for _, i := range hotGroupList {
var maxStage *uint16 = nil var maxStage *uint16 = nil
...@@ -1630,7 +1635,6 @@ func GetGroupByCountryV2(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -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) resp.ResponsePageOk(c, result, uint(total), pageIndex)
return myContext, nil return myContext, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment