Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

perf: optimize tag has new tag check

Sonui5f468c6f054a
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index 8010b5cd..71638e18 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -290,24 +290,18 @@ func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.T
func (ts *TagCommonService) HasNewTag(ctx context.Context, tags []*schema.TagItem) (bool, error) {
tagNames := make([]string, 0)
- tagMap := make(map[string]bool)
+ tagMap := make(map[string]struct{})
for _, item := range tags {
item.SlugName = strings.ReplaceAll(item.SlugName, " ", "-")
tagNames = append(tagNames, item.SlugName)
- tagMap[item.SlugName] = false
+ tagMap[item.SlugName] = struct{}{}
}
list, err := ts.GetTagListByNames(ctx, tagNames)
if err != nil {
return true, err
}
for _, item := range list {
- _, ok := tagMap[item.SlugName]
- if ok {
- tagMap[item.SlugName] = true
- }
- }
- for _, has := range tagMap {
- if !has {
+ if _, ok := tagMap[item.SlugName]; !ok {
return true, nil
}
}