Skip to content

Commit

Permalink
fix: user not existed and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
liaosunny123 committed Sep 1, 2023
1 parent 1bde059 commit 331bce9
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 44 deletions.
8 changes: 4 additions & 4 deletions .env.docker.compose
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CONSUL_ADDR=consul:8500
CONSUL_ANONYMITY_NAME=paraparty.
# Configure logger level, support: DEBUG, INFO, WARN (WARNING), ERROR, FATAL
LOGGER_LEVEL=INFO
LOGGER_LEVEL=DEBUG
# Cofigure logger integrated with otel, support: enable, disable
# If this setting is enable, you will see log in the OTEL Export with possible runtime waste
LOGGER_OUT_TRACING=enable
Expand Down Expand Up @@ -42,16 +42,16 @@ REDIS_DB=
REDIS_MASTER=
# Config Tracing EndPoint, support Jaeger
# Config state, if use `disable` the sampler will be closed. use `enable` to enable
TRACING_STATE=disable
TRACING_STATE=enable
# Config tracing sampler, suggest 0.01
TRACING_SAMPLER=0.01
TRACING_SAMPLER=1
TRACING_ENDPOINT=jaeger:4318
# Optional: Config Pyroscope
# Decide whether to enable the service, support : enable, disable.
# If you enable this service, you must provide Pyroscope server environment
# This profiling is ONLY designed for DEBUGGING
# SO, PLEASE DO NOT ENABLE THIS SERVICE IN YOUR PRODUCTION ENVIRONMENT, OR IT MAY TAKE MUCH RUNTIME COST.
PYROSCOPE_STATE=disable
PYROSCOPE_STATE=enable
PYROSCOPE_ADDR=http://pyroscope:4040/
# Configure RabbitMQ
# Optional: `RABBITMQ_VHOST_PREFIX`: If you provide this config, the service will use value as the rabbit mq vhost prefix.
Expand Down
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-auth-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-comment-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-event-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-favorite-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-feed-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-http-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-message-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-msg-consumer-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-publish-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
volumeMounts:
- mountPath: /data/apps/gugotik-service-bundle/data
name: volume
Expand Down
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-recommend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-relation-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-user-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
6 changes: 3 additions & 3 deletions manifests-endymx/deployment-video-processor-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ spec:
protocol: TCP
resources:
limits:
cpu: 8000m
cpu: 4000m
memory: 8Gi
requests:
cpu: 4000m
memory: 4Gi
cpu: 100m
memory: 128Mi
volumeMounts:
- mountPath: /data/apps/gugotik-service-bundle/data
name: volume
Expand Down
2 changes: 2 additions & 0 deletions src/constant/strings/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ const (
ChatActionLimitedError = "发送消息频繁,请稍后再试!"
FollowLimitedCode = 10012
FollowLimited = "关注频繁,请稍后再试!"
UserDoNotExistedCode = 10013
UserDoNotExisted = "查询用户不存在!"
)
7 changes: 7 additions & 0 deletions src/services/comment/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ func (c CommentServiceImpl) ActionComment(ctx context.Context, request *comment.
})

if err != nil || userResponse.StatusCode != strings.ServiceOKCode {
if userResponse.StatusCode == strings.UserNotExistedCode {
resp = &comment.ActionCommentResponse{
StatusCode: strings.UserDoNotExistedCode,
StatusMsg: strings.UserNotExisted,
}
return
}
logger.WithFields(logrus.Fields{
"err": err,
"ActorId": request.ActorId,
Expand Down
26 changes: 26 additions & 0 deletions src/services/favorite/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ func (c FavoriteServiceServerImpl) FavoriteList(ctx context.Context, req *favori
}, err
}

if !userResponse.Existed {
resp = &favorite.FavoriteListResponse{
StatusCode: strings.UserDoNotExistedCode,
StatusMsg: strings.UserDoNotExisted,
}
return
}

userId := fmt.Sprintf("%suser_like_%d", config.EnvCfg.RedisPrefix, req.UserId)
arr, err := redis2.Client.ZRevRange(ctx, userId, 0, -1).Result()
if err != nil {
Expand Down Expand Up @@ -499,6 +507,15 @@ func (c FavoriteServiceServerImpl) CountUserFavorite(ctx context.Context, req *f
StatusMsg: strings.FavoriteServiceError,
}, err
}

if !userResponse.Existed {
resp = &favorite.CountUserFavoriteResponse{
StatusCode: strings.UserDoNotExistedCode,
StatusMsg: strings.UserDoNotExisted,
}
return
}

user_like_id := fmt.Sprintf("%suser_like_%d", config.EnvCfg.RedisPrefix, req.UserId)

value, err := redis2.Client.ZCard(ctx, user_like_id).Result()
Expand Down Expand Up @@ -561,6 +578,15 @@ func (c FavoriteServiceServerImpl) CountUserTotalFavorited(ctx context.Context,
StatusMsg: strings.FavoriteServiceError,
}, err
}

if !userResponse.Existed {
resp = &favorite.CountUserTotalFavoritedResponse{
StatusCode: strings.UserDoNotExistedCode,
StatusMsg: strings.UserDoNotExisted,
}
return
}

user_liked_id := fmt.Sprintf("%suser_liked_%d", config.EnvCfg.RedisPrefix, req.UserId)

value, err := redis2.Client.Get(ctx, user_liked_id).Result()
Expand Down
15 changes: 11 additions & 4 deletions src/services/feed/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"GuGoTik/src/rpc/feed"
"GuGoTik/src/rpc/recommend"
"GuGoTik/src/rpc/user"
"GuGoTik/src/storage/cached"
"GuGoTik/src/storage/database"
"GuGoTik/src/storage/file"
grpc2 "GuGoTik/src/utils/grpc"
Expand Down Expand Up @@ -360,9 +361,15 @@ func (s FeedServiceImpl) QueryVideoExisted(ctx context.Context, req *feed.VideoE
logging.SetSpanWithHostname(span)
logger := logging.LogService("FeedService.QueryVideoExisted").WithContext(ctx)
var video models.Video
result := database.Client.WithContext(ctx).Where("id = ?", req.VideoId).First(&video)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
_, err = cached.GetWithFunc(ctx, "VideoExistedCached", func(ctx context.Context, key string) (string, error) {
row := database.Client.WithContext(ctx).Where("id = ?", req.VideoId).First(&video)
if row.Error != nil {
return "false", row.Error
}
return "true", nil
})
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
logger.WithFields(logrus.Fields{
"video_id": req.VideoId,
}).Warnf("gorm.ErrRecordNotFound")
Expand All @@ -383,7 +390,7 @@ func (s FeedServiceImpl) QueryVideoExisted(ctx context.Context, req *feed.VideoE
StatusMsg: strings.FeedServiceInnerError,
Existed: false,
}
return resp, result.Error
return resp, err
}
}
resp = &feed.VideoExistResponse{
Expand Down
14 changes: 14 additions & 0 deletions src/services/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ func (c MessageServiceImpl) ChatAction(ctx context.Context, request *chat.Action
}, err
}

if !userResponse.Existed {
return &chat.ActionResponse{
StatusCode: strings.UserDoNotExistedCode,
StatusMsg: strings.UserNotExisted,
}, nil
}

res, err = addMessage(ctx, request.ActorId, request.UserId, request.Content)
if err != nil {
logger.WithFields(logrus.Fields{
Expand Down Expand Up @@ -239,6 +246,13 @@ func (c MessageServiceImpl) Chat(ctx context.Context, request *chat.ChatRequest)
return
}

if !userResponse.Existed {
return &chat.ChatResponse{
StatusCode: strings.UserDoNotExistedCode,
StatusMsg: strings.UserNotExisted,
}, nil
}

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

Expand Down
Loading

0 comments on commit 331bce9

Please sign in to comment.