chore: remove existed tags in suggestion (#944)

This commit is contained in:
boojack
2023-01-13 22:37:30 +08:00
committed by GitHub
parent 10430a66c3
commit 219d2754a0
3 changed files with 36 additions and 27 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
"github.com/usememos/memos/api"
"github.com/usememos/memos/common"
"golang.org/x/exp/slices"
"github.com/labstack/echo/v4"
)
@@ -92,10 +93,24 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find memo list").SetInternal(err)
}
tagFind := &api.TagFind{
CreatorID: userID,
}
existTagList, err := s.Store.FindTagList(ctx, tagFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find tag list").SetInternal(err)
}
tagNameList := []string{}
for _, tag := range existTagList {
tagNameList = append(tagNameList, tag.Name)
}
tagMapSet := make(map[string]bool)
for _, memo := range memoList {
for _, tag := range findTagListFromMemoContent(memo.Content) {
tagMapSet[tag] = true
if !slices.Contains(tagNameList, tag) {
tagMapSet[tag] = true
}
}
}
tagList := []string{}