Skip to content

Fix redis empty category #982

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion server/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ func (s *RestServer) getTypedUserItemFeedback(request *restful.Request, response
itemId := request.PathParameter("item-id")
if feedback, err := s.DataClient.GetUserItemFeedback(ctx, userId, itemId, feedbackType); err != nil {
InternalServerError(response, err)
} else if feedbackType == "" {
} else if feedbackType == "" || len(feedback) == 0 {
Text(response, "{}")
} else {
Ok(response, feedback[0])
Expand Down
4 changes: 4 additions & 0 deletions storage/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ func decodeCategory(s string) (string, error) {
if err != nil {
return "", errors.Trace(err)
}
if len(b) == 0 {
return "", nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty category is _. You might represent "real" empty category by error or another return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dashboard just use the '' as the empty category, "_" is a internal value just used in the redis code. I think just return '' as the empty category is ok for now.
https://github.com/gorse-io/dashboard/blob/ed2e9e24e42b80e227a25dba70c48eb385cff91b/src/views/Item.vue#L199

}
return string(b[1:]), nil
}

Expand All @@ -496,6 +499,7 @@ func decodeCategories(s string) ([]string, error) {
if err != nil {
return nil, errors.Trace(err)
}
// category = "" is also a valid category
categories = append(categories, category)
}
return categories, nil
Expand Down
Loading