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.
refactor: remove redundant `len` and `nil` check
Eng Zer Junb6f0c70874a5
diff --git a/internal/base/server/http_funcmap.go b/internal/base/server/http_funcmap.goindex a64e49ea..0f99dca0 100644--- a/internal/base/server/http_funcmap.go+++ b/internal/base/server/http_funcmap.go@@ -143,15 +143,13 @@ var funcMap = template.FuncMap{func FormatLinkNofollow(html string) string {var hrefRegexp = regexp.MustCompile("(?m)<a.*?[^<]>.*?</a>")match := hrefRegexp.FindAllString(html, -1)- if match != nil {- for _, v := range match {- hasNofollow := strings.Contains(v, "rel=\"nofollow\"")- hasSiteUrl := strings.Contains(v, controller.SiteUrl)- if !hasSiteUrl {- if !hasNofollow {- nofollowUrl := strings.Replace(v, "<a", "<a rel=\"nofollow\"", 1)- html = strings.Replace(html, v, nofollowUrl, 1)- }+ for _, v := range match {+ hasNofollow := strings.Contains(v, "rel=\"nofollow\"")+ hasSiteUrl := strings.Contains(v, controller.SiteUrl)+ if !hasSiteUrl {+ if !hasNofollow {+ nofollowUrl := strings.Replace(v, "<a", "<a rel=\"nofollow\"", 1)+ html = strings.Replace(html, v, nofollowUrl, 1)}}}diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.goindex 51495a46..67996164 100644--- a/internal/repo/search_common/search_repo.go+++ b/internal/repo/search_common/search_repo.go@@ -146,22 +146,20 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDsub.Where(likeConA)// check tag- if len(tagIDs) > 0 {- for ti, tagID := range tagIDs {- ast := "tag_rel" + strconv.Itoa(ti)- b.Join("INNER", "tag_rel as "+ast, "question.id = "+ast+".object_id").- And(builder.Eq{- ast + ".tag_id": tagID,- ast + ".status": entity.TagRelStatusAvailable,- })- ub.Join("INNER", "tag_rel as "+ast, "question_id = "+ast+".object_id").- And(builder.Eq{- ast + ".tag_id": tagID,- ast + ".status": entity.TagRelStatusAvailable,- })- argsQ = append(argsQ, entity.TagRelStatusAvailable, tagID)- argsA = append(argsA, entity.TagRelStatusAvailable, tagID)- }+ for ti, tagID := range tagIDs {+ ast := "tag_rel" + strconv.Itoa(ti)+ b.Join("INNER", "tag_rel as "+ast, "question.id = "+ast+".object_id").+ And(builder.Eq{+ ast + ".tag_id": tagID,+ ast + ".status": entity.TagRelStatusAvailable,+ })+ ub.Join("INNER", "tag_rel as "+ast, "question_id = "+ast+".object_id").+ And(builder.Eq{+ ast + ".tag_id": tagID,+ ast + ".status": entity.TagRelStatusAvailable,+ })+ argsQ = append(argsQ, entity.TagRelStatusAvailable, tagID)+ argsA = append(argsA, entity.TagRelStatusAvailable, tagID)}// check user@@ -265,16 +263,14 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, tagIDb.Where(likeConQ)// check tag- if len(tagIDs) > 0 {- for ti, tagID := range tagIDs {- ast := "tag_rel" + strconv.Itoa(ti)- b.Join("INNER", "tag_rel as "+ast, "question.id = "+ast+".object_id").- And(builder.Eq{- ast + ".tag_id": tagID,- ast + ".status": entity.TagRelStatusAvailable,- })- args = append(args, entity.TagRelStatusAvailable, tagID)- }+ for ti, tagID := range tagIDs {+ ast := "tag_rel" + strconv.Itoa(ti)+ b.Join("INNER", "tag_rel as "+ast, "question.id = "+ast+".object_id").+ And(builder.Eq{+ ast + ".tag_id": tagID,+ ast + ".status": entity.TagRelStatusAvailable,+ })+ args = append(args, entity.TagRelStatusAvailable, tagID)}// check need filter has not accepted@@ -376,16 +372,14 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDsb.Where(likeConA)// check tag- if len(tagIDs) > 0 {- for ti, tagID := range tagIDs {- ast := "tag_rel" + strconv.Itoa(ti)- b.Join("INNER", "tag_rel as "+ast, "question_id = "+ast+".object_id").- And(builder.Eq{- ast + ".tag_id": tagID,- ast + ".status": entity.TagRelStatusAvailable,- })- args = append(args, entity.TagRelStatusAvailable, tagID)- }+ for ti, tagID := range tagIDs {+ ast := "tag_rel" + strconv.Itoa(ti)+ b.Join("INNER", "tag_rel as "+ast, "question_id = "+ast+".object_id").+ And(builder.Eq{+ ast + ".tag_id": tagID,+ ast + ".status": entity.TagRelStatusAvailable,+ })+ args = append(args, entity.TagRelStatusAvailable, tagID)}// check limit accepted