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

feat: Application details have been enhanced with tags. #7777

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

zhengkunwang223
Copy link
Member

@zhengkunwang223 zhengkunwang223 commented Jan 27, 2025

Refs #7774

Copy link

f2c-ci-robot bot commented Jan 27, 2025

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
}

Copy link
Member

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
}
Copy link
Member

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:

  1. 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 {
Copy link
Member

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:

  1. The models package may have been updated with new tag data structures that support JSON serialization better than Go's built-in tag types.
  2. These new tags might include additional fields or complex relationships compared to the existing ones.
  3. 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.

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

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

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Jan 27, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit 57bfc38 into dev Jan 27, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev@website branch January 27, 2025 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants