by Robin at 20240621
This commit is contained in:
parent
41cf08be7c
commit
177a95ac35
|
@ -5,10 +5,11 @@ import "service/api/base"
|
|||
// 根据UserId模糊查询(和姓名取并集)
|
||||
type OpListFuzzilyByUserIdReq struct {
|
||||
base.BaseRequest
|
||||
UserIdString string `json:"user_id_string"` //user_id模糊匹配
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort []string
|
||||
UserIdString string `json:"user_id_string"` //user_id模糊匹配
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort []string
|
||||
BlockedFromBeingSearchedList []string
|
||||
}
|
||||
|
||||
type OpListFuzzilyByUserIdData struct {
|
||||
|
@ -22,10 +23,11 @@ type OpListFuzzilyByUserIdResp struct {
|
|||
// 根据Name模糊查询
|
||||
type OpListFuzzilyByNameReq struct {
|
||||
base.BaseRequest
|
||||
Name string `json:"name"` //name模糊匹配
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort []string
|
||||
Name string `json:"name"` //name模糊匹配
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort []string
|
||||
BlockedFromBeingSearchedList []string
|
||||
}
|
||||
|
||||
type OpListFuzzilyByNameData struct {
|
||||
|
|
|
@ -89,9 +89,9 @@ func (es *ElasticSearch) GetStreamerAcctListFuzzilyByName(ctx *gin.Context, req
|
|||
pinyinClause = elastic.NewMatchPhraseQuery("pinyin.long_char", req.Name)
|
||||
}
|
||||
orClause := elastic.NewBoolQuery().Should(nameClause, pinyinClause)
|
||||
query := elastic.NewBoolQuery().Must()
|
||||
delFlagClause := elastic.NewMatchQuery("del_flag", 0)
|
||||
query.Must(orClause, delFlagClause)
|
||||
mustnotClause := elastic.NewTermsQueryFromStrings("_id", req.BlockedFromBeingSearchedList...)
|
||||
query := elastic.NewBoolQuery().Must(orClause, delFlagClause).MustNot(mustnotClause)
|
||||
|
||||
res, err := es.clientMix.Search(es.getIndexStreamerAcct()).Query(query).From(req.Offset).Size(req.Limit).Sort("ct", true).Do(ctx)
|
||||
if err != nil {
|
||||
|
@ -135,9 +135,9 @@ func (es *ElasticSearch) GetStreamerAcctListFuzzilyByUserId(ctx *gin.Context, re
|
|||
userIdStringClause = elastic.NewMatchPhraseQuery("user_id_string.long_char", req.UserIdString)
|
||||
}
|
||||
orClause := elastic.NewBoolQuery().Should(nameClause, userIdStringClause)
|
||||
query := elastic.NewBoolQuery().Must()
|
||||
delFlagClause := elastic.NewMatchQuery("del_flag", 0)
|
||||
query.Must(orClause, delFlagClause)
|
||||
mustnotClause := elastic.NewTermsQueryFromStrings("_id", req.BlockedFromBeingSearchedList...)
|
||||
query := elastic.NewBoolQuery().Must(orClause, delFlagClause).MustNot(mustnotClause)
|
||||
|
||||
res, err := es.clientMix.Search(es.getIndexStreamerAcct()).Query(query).From(req.Offset).Size(req.Limit).Sort("ct", true).Do(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -37,6 +37,7 @@ import (
|
|||
"service/dbstruct"
|
||||
"service/library/apollo"
|
||||
"service/library/logger"
|
||||
"service/library/redis"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -1226,12 +1227,21 @@ func (s *Service) ApiGetStreamerExtListFuzzilyByUserId(ctx *gin.Context, req *st
|
|||
|
||||
ec = errcode.ErrCodeStreamerSrvOk
|
||||
|
||||
// 从redis中获取当前禁止被搜索的主播
|
||||
blockedlist := make([]string, 0)
|
||||
err := redis.GetRedisClient().GetObject(consts.RedisStreamerPrefix+"blocked_from_being_searched_list", &blockedlist)
|
||||
if err != nil {
|
||||
logger.Error("Redis read failed : %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
//1.从主播用户表中模糊匹配所有主播信息的用户侧数据,按mid正序排序
|
||||
streameraccts, err := _DefaultStreamerAcct.OpListStreamerAcctFuzzilyByUserId(ctx, &streameracctproto.OpListFuzzilyByUserIdReq{
|
||||
UserIdString: fmt.Sprint(util.DerefInt64(req.UserId)),
|
||||
Offset: req.Offset,
|
||||
Limit: req.Limit,
|
||||
Sort: []string{"_id"},
|
||||
UserIdString: fmt.Sprint(util.DerefInt64(req.UserId)),
|
||||
Offset: req.Offset,
|
||||
Limit: req.Limit,
|
||||
Sort: []string{"_id"},
|
||||
BlockedFromBeingSearchedList: blockedlist,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("StreamerAcct OpListFuzzilyByUserId fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
|
@ -1263,12 +1273,21 @@ func (s *Service) ApiGetStreamerExtListFuzzilyByName(ctx *gin.Context, req *stre
|
|||
|
||||
ec = errcode.ErrCodeStreamerSrvOk
|
||||
|
||||
// 从redis中获取当前禁止被搜索的主播
|
||||
blockedlist := make([]string, 0)
|
||||
err := redis.GetRedisClient().GetObject(consts.RedisStreamerPrefix+"blocked_from_being_searched_list", &blockedlist)
|
||||
if err != nil {
|
||||
logger.Error("Redis read failed : %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
//1.从主播用户表中模糊匹配所有主播信息的用户侧数据,按mid正序排序
|
||||
streameraccts, err := _DefaultStreamerAcct.OpListStreamerAcctFuzzilyByName(ctx, &streameracctproto.OpListFuzzilyByNameReq{
|
||||
Name: req.Name,
|
||||
Offset: req.Offset,
|
||||
Limit: req.Limit,
|
||||
Sort: []string{"_id"},
|
||||
Name: req.Name,
|
||||
Offset: req.Offset,
|
||||
Limit: req.Limit,
|
||||
Sort: []string{"_id"},
|
||||
BlockedFromBeingSearchedList: blockedlist,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("Account OpListFuzzilyByName fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
|
|
|
@ -84,6 +84,7 @@ func (s *CronService) Init(c any) (exec xxl.Executor, err error) {
|
|||
exec.RegTask("video_moderation_batch", s.VideoModerationBatch)
|
||||
exec.RegTask("video_moderation_batch_his", s.VideoModerationBatchHis)
|
||||
exec.RegTask("clear_expired_btcb", s.ClearExpiredBtcb)
|
||||
exec.RegTask("reload_blocked_from_being_searched_list", s.ReloadBlockedFromBeingSearchedList)
|
||||
exec.LogHandler(customLogHandle)
|
||||
//注册任务handler
|
||||
|
||||
|
|
|
@ -580,3 +580,31 @@ func (s *CronService) ClearExpiredBtcb(ctx context.Context, param *xxl.RunReq) (
|
|||
logger.Info("Clear expired btcb ends...")
|
||||
return "Clear expired btcb ends..."
|
||||
}
|
||||
|
||||
func (s *CronService) ReloadBlockedFromBeingSearchedList(ctx context.Context, param *xxl.RunReq) (msg string) {
|
||||
logger.Info("task %v param: %v log_id: %v", param.ExecutorHandler, param.ExecutorParams, xxl.Int64ToStr(param.LogID))
|
||||
logger.Info("Refreshing blocked-from-being-searched list cached in redis...")
|
||||
|
||||
// 查找禁止在搜索被发现的主播
|
||||
list, err := _DefaultAccountPunishment.OpListByType(&gin.Context{}, consts.AccountPunishment_BlockFromBeingSearched)
|
||||
if err != nil {
|
||||
logger.Error("_DefaultAccountPunishment OpListByType fail, err: %v", err)
|
||||
}
|
||||
// 清缓存
|
||||
if err := redis.GetRedisClient().Del(consts.RedisStreamerPrefix + "blocked_from_being_searched_list"); err != nil {
|
||||
logger.Error("Del redis cache fail, err: %v", err)
|
||||
return fmt.Sprintf("Del redis cache fail, err: %v", err)
|
||||
}
|
||||
|
||||
// 加载缓存
|
||||
for _, acctpunishment := range list {
|
||||
err := redis.GetRedisClient().RPush(consts.RedisStreamerPrefix+"blocked_from_being_searched_list", fmt.Sprint(acctpunishment.GetMid()))
|
||||
if err != nil {
|
||||
logger.Error("Redis cache fail, err: %v", err)
|
||||
return fmt.Sprintf("Redis cache fail, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("Refresh blocked-from-being-searched list cached in redis accomplished...")
|
||||
return "Refresh blocked-from-being-searched list cached in redis accomplished"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue