You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/07/12 08:40:14 UTC

(incubator-answer) 02/02: feat(tag): recommend tags can't contain reserved tag

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.3.6/template
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit c4318f1d18f96d73b9e2b90458f8ad5c2ece62e0
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Fri Jul 12 16:40:02 2024 +0800

    feat(tag): recommend tags can't contain reserved tag
---
 internal/service/siteinfo/siteinfo_service.go | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
index c7f1f9ce..ce71900d 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -181,11 +181,23 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site
 // SaveSiteWrite save site configuration about write
 func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (resp interface{}, err error) {
 	recommendTags, reservedTags := make([]string, 0), make([]string, 0)
-	for _, tag := range req.RecommendTags {
-		recommendTags = append(recommendTags, tag.SlugName)
-	}
+	recommendTagMapping, reservedTagMapping := make(map[string]bool), make(map[string]bool)
 	for _, tag := range req.ReservedTags {
-		reservedTags = append(reservedTags, tag.SlugName)
+		if !recommendTagMapping[tag.SlugName] {
+			reservedTagMapping[tag.SlugName] = true
+			reservedTags = append(reservedTags, tag.SlugName)
+		}
+	}
+
+	// recommend tags can't contain reserved tag
+	for _, tag := range req.RecommendTags {
+		if reservedTagMapping[tag.SlugName] {
+			continue
+		}
+		if !recommendTagMapping[tag.SlugName] {
+			recommendTagMapping[tag.SlugName] = true
+			recommendTags = append(recommendTags, tag.SlugName)
+		}
 	}
 	errData, err := s.tagCommonService.SetSiteWriteTag(ctx, recommendTags, reservedTags, req.UserID)
 	if err != nil {