Commit 2fa621ef authored by hujiebin's avatar hujiebin

清理15天之前的访客

parent 52248445
...@@ -66,8 +66,10 @@ func GetUserRecentRooms(model *domain.Model, userId uint64) (imGroupIds []string ...@@ -66,8 +66,10 @@ func GetUserRecentRooms(model *domain.Model, userId uint64) (imGroupIds []string
// 15天前访问的 // 15天前访问的
func RemoveRoomVisitors(model *domain.Model, imGroupId string) { func RemoveRoomVisitors(model *domain.Model, imGroupId string) {
groupKey := group_k.GetUserEnterRoomGroupKey(imGroupId) groupKey := group_k.GetUserEnterRoomGroupKey(imGroupId)
err := model.Redis.ZRemRangeByScore(model, groupKey, "-inf", fmt.Sprintf("%d", time.Now().AddDate(0, 0, -15).Unix())).Err() n, err := model.Redis.ZRemRangeByScore(model, groupKey, "-inf", fmt.Sprintf("%d", time.Now().AddDate(0, 0, -15).Unix())).Result()
if err != nil { if err != nil {
model.Log.Errorf("RemoveRoomVisitors fail:%v", err) model.Log.Errorf("RemoveRoomVisitors fail:%v", err)
} else {
model.Log.Infof("RemoveRoomVisitors key:%v,n:%v", groupKey, n)
} }
} }
...@@ -973,6 +973,8 @@ func GetGroupVisitors(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -973,6 +973,8 @@ func GetGroupVisitors(c *gin.Context) (*mycontext.MyContext, error) {
} }
} }
resp.ResponseOk(c, result) resp.ResponseOk(c, result)
// 清理15天之前的访客
group_c.RemoveRoomVisitors(model, groupId)
return myContext, nil return myContext, nil
} }
......
...@@ -2,6 +2,7 @@ package test ...@@ -2,6 +2,7 @@ package test
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"hilo-group/domain/cache/group_c"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"testing" "testing"
) )
...@@ -23,3 +24,7 @@ func TestGetUserVipMap(t *testing.T) { ...@@ -23,3 +24,7 @@ func TestGetUserVipMap(t *testing.T) {
res, err := user_m.BatchGetVips(userIds) res, err := user_m.BatchGetVips(userIds)
t.Logf("%v-%v", res, err) t.Logf("%v-%v", res, err)
} }
func TestRemoveRoomVisit(t *testing.T) {
group_c.RemoveRoomVisitors(domain.CreateModelNil(), "HTGS#a47478749")
}
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