Skip to content

Commit

Permalink
perf: only get meta tags for non-empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Nov 25, 2024
1 parent 0986a40 commit 679000a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions internal/search/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,28 @@ func (c *client) Handle(ctx echo.Context) error {
return errgo.Wrap(err, "subjectRepo.GetByIDs")
}

// tags, err := c.tagRepo.GetByIDs(ctx.Request().Context(), ids)
// if err != nil {
// return errgo.Wrap(err, "tagRepo.GetByIDs")
// }
var idsToGetTags []model.SubjectID
for _, m := range subjects {
if m.MetaTags != "" {
idsToGetTags = append(idsToGetTags, m.ID)
}
}

tags, err := c.tagRepo.GetByIDs(ctx.Request().Context(), idsToGetTags)
if err != nil {
return errgo.Wrap(err, "tagRepo.GetByIDs")
}

var data = make([]ReponseSubject, 0, len(subjects))
for _, id := range ids {
s, ok := subjects[id]
if !ok {
continue
}
// metaTags := tags[id]
var metaTags []tag.Tag
metaTags := tags[id]
if metaTags == nil {
metaTags = []tag.Tag{}
}

for _, t := range strings.Split(s.MetaTags, " ") {
metaTags = append(metaTags, tag.Tag{Name: t, Count: 1})
Expand Down

0 comments on commit 679000a

Please sign in to comment.