This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch dev in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 5af69352b546a21ebabe7a570c355e3f6b995bb1 Author: Sonui <[email protected]> AuthorDate: Sat Oct 26 18:21:14 2024 +0800 perf: optimize tag has new tag check --- internal/service/tag_common/tag_common.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) 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 } }
