Merge pull request 'by Robin at 20240119; fix' (#62) from feat-20240119-001-Robin into main

Reviewed-on: #62
This commit is contained in:
chenhao 2024-01-19 18:08:29 +08:00
commit 9b70fb5ac8
3 changed files with 35 additions and 1 deletions

View File

@ -34,6 +34,7 @@ const (
MaxDailyVeriCodeSendTimesKey = "max_daily_veri_code_send_times"
ImageIdForUploadFail = "image_id_for_upload_fail"
VideoIdForUploadFail = "video_id_for_upload_fail"
RestrictedVisitorKey = "restricted_visitor"
)
// del_flag

View File

@ -0,0 +1,7 @@
package apollostruct
// 账户初始化数据
type RestrictedVisitorCfg struct {
RestrictedVisitorMids []int64 `json:"restricted_visitor_mids"` // 限制可见范围的访客mids
RestrictedVisitorVisibleMids []int64 `json:"restricted_visitor_visible_mids"` // 限制访客可见的mids
}

View File

@ -1213,8 +1213,16 @@ func (s *Service) ApiGetStreamerRecommList(ctx *gin.Context, req *streamerproto.
ec = errcode.ErrCodeStreamerSrvOk
// 取apollo配置
cfg := &apollostruct.RestrictedVisitorCfg{}
err := apollo.GetJson(consts.RestrictedVisitorKey, &cfg, apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
return nil, errcode.ErrCodeApolloReadFail
}
//1.从redis中获取数据
err := redis.GetRedisClient().GetObject(consts.RedisStreamerPrefix+"recomm_list", &recommlist)
err = redis.GetRedisClient().GetObject(consts.RedisStreamerPrefix+"recomm_list", &recommlist)
if err != nil {
logger.Error("Redis read failed : %v", err)
ec = errcode.ErrCodeStreamerRecommListRedisCacheInvalid
@ -1255,6 +1263,24 @@ func (s *Service) ApiGetStreamerRecommList(ctx *gin.Context, req *streamerproto.
}
}
visitorMid := req.BaseRequest.Mid
for _, restricted_visitor_mid := range cfg.RestrictedVisitorMids {
if restricted_visitor_mid == visitorMid { // 是限制访问的访客
recommMap := make(map[int64]int64)
for _, recommMid := range recommlist {
recommMap[recommMid] = 1
}
restrictedRecommList := make([]int64, 0)
for _, restrictedVisitorVisibleMid := range cfg.RestrictedVisitorVisibleMids {
if recommMap[restrictedVisitorVisibleMid] == 1 {
restrictedRecommList = append(restrictedRecommList, restrictedVisitorVisibleMid)
}
}
recommlist = restrictedRecommList
break
}
}
return
}