diff --git a/api/proto/streamer_acct/proto/streamer_acct_op.go b/api/proto/streamer_acct/proto/streamer_acct_op.go index 5e3ec58a..85d62830 100644 --- a/api/proto/streamer_acct/proto/streamer_acct_op.go +++ b/api/proto/streamer_acct/proto/streamer_acct_op.go @@ -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 { diff --git a/app/mix/dao/elasticsearch.go b/app/mix/dao/elasticsearch.go index 1c0ff038..9db99118 100644 --- a/app/mix/dao/elasticsearch.go +++ b/app/mix/dao/elasticsearch.go @@ -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 { diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index b6b96d69..fb7f6999 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -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) diff --git a/app/mix/service/cronservice.go b/app/mix/service/cronservice.go index a56316cc..b1c58abf 100644 --- a/app/mix/service/cronservice.go +++ b/app/mix/service/cronservice.go @@ -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 diff --git a/app/mix/service/xxljob_tasks.go b/app/mix/service/xxljob_tasks.go index 1c3d05fb..899f8fa0 100644 --- a/app/mix/service/xxljob_tasks.go +++ b/app/mix/service/xxljob_tasks.go @@ -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" +}