LinkinStars commented on code in PR #701:
URL: https://github.com/apache/incubator-answer/pull/701#discussion_r1437961097
##########
internal/service/question_service.go:
##########
@@ -1237,7 +1241,17 @@ func (qs *QuestionService) SimilarQuestion(ctx
context.Context, questionID strin
func (qs *QuestionService) GetQuestionPage(ctx context.Context, req
*schema.QuestionPageReq) (
questions []*schema.QuestionPageResp, total int64, err error) {
questions = make([]*schema.QuestionPageResp, 0)
-
+ // query by user role
+ req.ShowHidden = false
+ if req.LoginUserID != "" {
+ userRole, err := qs.userRoleRelService.GetUserRole(ctx,
req.LoginUserID)
+ if err != nil {
+ return nil, 0, err
+ }
+ if req.UserIDBeSearched != "" {
+ req.ShowHidden = req.LoginUserID ==
req.UserIDBeSearched || userRole == role.RoleAdminID || userRole ==
role.RoleModeratorID
+ }
+ }
Review Comment:
1. Currently, you don't need to put the ShowHidden variable as a parameter
to the req. That would make the caller wonder if they need to pass that
parameter. For now, this is the only place this parameter is used.
2. Sometimes it is possible to reduce the number of queries for a role by
one.
This is a reference case. Would that be better?
```go
showHidden := false
if req.LoginUserID != "" && req.UserIDBeSearched != "" {
showHidden = req.LoginUserID == req.UserIDBeSearched
if !showHidden {
userRole, err := qs.userRoleRelService.GetUserRole(ctx,
req.LoginUserID)
if err != nil {
return nil, 0, err
}
showHidden = userRole == role.RoleAdminID || userRole
== role.RoleModeratorID
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]