-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat: Application details have been enhanced with tags. #7777
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
if err != nil { | ||
return nil, err | ||
} | ||
appDTO.Tags = tags | ||
return &appDTO, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review:
The function PageApp
has a minor issue where it continues running even if there is an error retrieving app tags. It would be better to return early with an appropriate error when encountering any errors.
In the GetApp
function, there is unnecessary conversion of the language to lowercase in the call to getAppTags
.
Here's the optimized version:
func (a AppService) PageApp(ctx *gin.Context, req request.AppSearch) (interface{}, error) {
...
appTags, err := getAppTags(ap.ID, langs[i])
if err != nil {
return nil, err
}
...
}
func (a AppService) GetApp(ctx *gin.Context, key string) (*response.AppDTO, error) {
...
tags, err := getAllTags(appID)
if err != nil {
return nil, err
}
This makes the code cleaner and more readable. The use of slices (langs
) and loop can also make the logic more flexible for handling different languages.
} | ||
} | ||
return res, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is mostly clean, but there are a few areas that could be improved:
-
Variable Scope: The
tagDTO
variable within the loop should likely be declared outside of the loops for better readability and maintainability.
var tagDTO response.TagDTO
for _, t := range appTags {
// ...
}
for _, t := range tags {
// Use tagDTO here
}
2. **JSON Parsing Error Handling**: Although not shown in this snippet, ensure that JSON parsing errors are handled properly to prevent panics or undefined behavior.
3. **Performance**:
- If the number of application tags and translations grows significantly, consider caching results to avoid repeated database queries.
- If multiple threads access these methods concurrently without proper synchronization, it could lead to race conditions.
4. **Docstring Comments**:
Add docstrings to explain what each method does and its parameters/return values.
5. **Unused Variables**: Remove unused variables from comments if they no longer have meaningful context.
Overall, the primary concern seems to be the reusability and efficiency of accessing related data from two different repositories based on the language. Caching could help solve this issue more broadly.
Tags []model.Tag `json:"tags"` | ||
Installed bool `json:"installed"` | ||
Versions []string `json:"versions"` | ||
Tags []TagDTO `json:"tags"` | ||
} | ||
|
||
type AppItem struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in the AppDTO
structure involve replacing the embedded model.Tag
slice with an array of TagDTO
slices. This suggests that:
- The
models
package may have been updated with new tag data structures that support JSON serialization better than Go's built-in tag types. - These new tags might include additional fields or complex relationships compared to the existing ones.
- Ensure compatibility with any external systems that read this DTO by validating against their specifications.
To implement these changes:
type TagDTO struct {
TagName string // Example field, replace with appropriate tagging logic or structure from models package.
Description string `json:"description"` // Similar example for description.
}
In your main application code where you use this AppDTO
, update how you handle reading and writing Tags
. If TagDTO
includes new members or requires initialization differently, adjust accordingly.
After implementation:
- Re-run unit tests to ensure correctness.
- Review documentation around API contracts to make sure it reflects the changes accurately.
Ensure that no old clients relying on outdated tag formats are affected by these changes.
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Refs #7774