Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dead circulation #168

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/services/favorite/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (c FavoriteServiceServerImpl) FavoriteAction(ctx context.Context, req *favo
val = -1
}
videoId := fmt.Sprintf("%svideo_like_%d", config.EnvCfg.RedisPrefix, req.VideoId) // 该视频的点赞数量
user_like_Id := fmt.Sprintf("%suser_like_%d", config.EnvCfg.RedisPrefix, req.ActorId) // 用户的点赞数量
user_like_Id := fmt.Sprintf("%suser_like_%d", config.EnvCfg.RedisPrefix, req.ActorId) // 用户的点赞
user_liked_id := fmt.Sprintf("%suser_liked_%d", config.EnvCfg.RedisPrefix, user_liked) // 被赞用户的获赞数量
pipe.IncrBy(ctx, videoId, val)
pipe.IncrBy(ctx, user_liked_id, val)
Expand Down Expand Up @@ -149,9 +149,8 @@ func (c FavoriteServiceServerImpl) FavoriteList(ctx context.Context, req *favori
}).Debugf("Process start")

//以下判断用户是否合法,我觉得大可不必
userResponse, err := userClient.GetUserInfo(ctx, &user.UserRequest{
UserId: req.ActorId,
ActorId: req.UserId,
userResponse, err := userClient.GetUserExistInformation(ctx, &user.UserExistRequest{
UserId: req.UserId,
})

if err != nil || userResponse.StatusCode != strings.ServiceOKCode {
Expand Down Expand Up @@ -235,9 +234,8 @@ func (c FavoriteServiceServerImpl) IsFavorite(ctx context.Context, req *favorite
"video_id": req.VideoId,
}).Debugf("Process start")
//判断视频id是否存在,我觉得大可不必
value, err := feedClient.QueryVideos(ctx, &feed.QueryVideosRequest{
ActorId: req.ActorId,
VideoIds: []uint32{req.VideoId},
value, err := feedClient.QueryVideoExisted(ctx, &feed.VideoExistRequest{
VideoId: req.VideoId,
})
if err != nil || value.StatusCode != strings.ServiceOKCode {
logger.WithFields(logrus.Fields{
Expand Down Expand Up @@ -303,7 +301,20 @@ func (c FavoriteServiceServerImpl) CountFavorite(ctx context.Context, req *favor
logger.WithFields(logrus.Fields{
"video_id": req.VideoId,
}).Debugf("Process start")

//判断视频id是否存在,我觉得大可不必
Vresp, err := feedClient.QueryVideoExisted(ctx, &feed.VideoExistRequest{
VideoId: req.VideoId,
})
if err != nil || Vresp.StatusCode != strings.ServiceOKCode {
logger.WithFields(logrus.Fields{
"user_id": req.VideoId,
}).Errorf("feed Service error")
logging.SetSpanError(span, err)
return &favorite.CountFavoriteResponse{
StatusCode: strings.FavorivateServiceErrorCode,
StatusMsg: strings.FavorivateServiceError,
}, err
}
videoId := fmt.Sprintf("%svideo_like_%d", config.EnvCfg.RedisPrefix, req.VideoId)
value, err := redis2.Client.Get(ctx, videoId).Result()
var num int
Expand Down Expand Up @@ -346,9 +357,8 @@ func (c FavoriteServiceServerImpl) CountUserFavorite(ctx context.Context, req *f
}).Debugf("Process start")

//以下判断用户是否合法,我觉得大可不必
userResponse, err := userClient.GetUserInfo(ctx, &user.UserRequest{
ActorId: 1,
UserId: req.UserId,
userResponse, err := userClient.GetUserExistInformation(ctx, &user.UserExistRequest{
UserId: req.UserId,
})

if err != nil || userResponse.StatusCode != strings.ServiceOKCode {
Expand Down Expand Up @@ -407,9 +417,8 @@ func (c FavoriteServiceServerImpl) CountUserTotalFavorited(ctx context.Context,
}).Debugf("Process start")

//以下判断用户是否合法,我觉得大可不必
userResponse, err := userClient.GetUserInfo(ctx, &user.UserRequest{
ActorId: req.ActorId,
UserId: req.UserId,
userResponse, err := userClient.GetUserExistInformation(ctx, &user.UserExistRequest{
UserId: req.UserId,
})

if err != nil || userResponse.StatusCode != strings.ServiceOKCode {
Expand Down
27 changes: 23 additions & 4 deletions src/services/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ func (c MessageServiceImpl) ChatAction(ctx context.Context, request *chat.Action
"content_text": request.Content,
}).Debugf("Process start")

userResponse, err := UserClient.GetUserInfo(ctx, &user.UserRequest{
ActorId: request.ActorId,
UserId: request.UserId,
userResponse, err := UserClient.GetUserExistInformation(ctx, &user.UserExistRequest{
UserId: request.UserId,
})

if err != nil || userResponse.StatusCode != strings.ServiceOKCode {
Expand Down Expand Up @@ -89,6 +88,26 @@ func (c MessageServiceImpl) Chat(ctx context.Context, request *chat.ChatRequest)
"ActorId": request.ActorId,
"pre_msg_time": request.PreMsgTime,
}).Debugf("Process start")

userResponse, err := UserClient.GetUserExistInformation(ctx, &user.UserExistRequest{
UserId: request.UserId,
})

if err != nil || userResponse.StatusCode != strings.ServiceOKCode {
logger.WithFields(logrus.Fields{
"err": err,
"ActorId": request.ActorId,
"user_id": request.UserId,
}).Errorf("User service error")
logging.SetSpanError(span, err)

resp = &chat.ChatResponse{
StatusCode: strings.UnableToQueryMessageErrorCode,
StatusMsg: strings.UnableToQueryMessageError,
}
return
}

toUserId := request.UserId
fromUserId := request.ActorId

Expand All @@ -98,7 +117,7 @@ func (c MessageServiceImpl) Chat(ctx context.Context, request *chat.ChatRequest)
conversationId = fmt.Sprintf("%d_%d", fromUserId, toUserId)
}
//这个地方应该取出多少条消息?
//TO DO 看怎么需要一下
//TO DO 看怎么需要改一下

var pMessageList []models.Message
result := database.Client.WithContext(ctx).
Expand Down
Loading