fix: tags will not be synced to search plugin when adding new question (#697)

fix #696 .

changes,
1. change `qr.updateSearch` to `qr.UpdateSearch` to make it accessible
outside.
2. update search (search plugin) after updating or adding records in the
`TagRel` table.

---------

Signed-off-by: Adam Vollrath <adam.d.vollrath@gmail.com>
Co-authored-by: sy-records <52o@qq52o.cn>
Co-authored-by: Adam Vollrath <adam.d.vollrath@gmail.com>
Co-authored-by: kumfo <kumfo@sifou.com>
This commit is contained in:
Han Gao
2023-12-26 14:26:12 +08:00
committed by GitHub
parent ab2be1479b
commit ec11a126c4
34 changed files with 65 additions and 65 deletions
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -732,7 +732,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -674,7 +674,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -428,7 +428,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -466,7 +466,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+2 -2
View File
@@ -433,7 +433,7 @@ ui:
range: Display name up to 35 characters.
slug_name:
label: URL Slug
desc: 'Must use the character set "a-z", "0-9", "+ # - ."'
desc: URL slug up to 35 characters.
msg:
empty: URL slug cannot be empty.
range: URL slug up to 35 characters.
@@ -471,7 +471,7 @@ ui:
label: Display Name
slug_name:
label: URL Slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Açıklama
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: 'Must use the character set "a-z", "0-9", "+ # - ."'
info: URL slug up to 35 characters.
desc:
label: Description
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: 显示名称
slug_name:
label: URL 固定链接
info: '必须由 "a-z", "0-9", "+ # - ." 组成'
info: URL 固定链接不能超过 35 个字符。
desc:
label: 描述
edit_summary:
+1 -1
View File
@@ -716,7 +716,7 @@ ui:
label: Display name
slug_name:
label: URL slug
info: '必須由 "a-z", "0-9", "+ # - ." 組成'
info: URL slug 不能超過 35 個字符。
desc:
label: 描述
edit_summary:
+12 -14
View File
@@ -39,11 +39,10 @@ import (
"github.com/apache/incubator-answer/pkg/htmltext"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/apache/incubator-answer/plugin"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
"xorm.io/builder"
"xorm.io/xorm"
"github.com/segmentfault/pacman/errors"
)
// questionRepo question repository
@@ -76,7 +75,6 @@ func (qr *questionRepo) AddQuestion(ctx context.Context, question *entity.Questi
if handler.GetEnableShortID(ctx) {
question.ID = uid.EnShortID(question.ID)
}
_ = qr.updateSearch(ctx, question.ID)
return
}
@@ -100,7 +98,7 @@ func (qr *questionRepo) UpdateQuestion(ctx context.Context, question *entity.Que
if handler.GetEnableShortID(ctx) {
question.ID = uid.EnShortID(question.ID)
}
_ = qr.updateSearch(ctx, question.ID)
_ = qr.UpdateSearch(ctx, question.ID)
return
}
@@ -111,7 +109,7 @@ func (qr *questionRepo) UpdatePvCount(ctx context.Context, questionID string) (e
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, question.ID)
_ = qr.UpdateSearch(ctx, question.ID)
return nil
}
@@ -123,7 +121,7 @@ func (qr *questionRepo) UpdateAnswerCount(ctx context.Context, questionID string
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, question.ID)
_ = qr.UpdateSearch(ctx, question.ID)
return nil
}
@@ -155,7 +153,7 @@ func (qr *questionRepo) UpdateQuestionStatus(ctx context.Context, questionID str
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, questionID)
_ = qr.UpdateSearch(ctx, questionID)
return nil
}
@@ -165,7 +163,7 @@ func (qr *questionRepo) UpdateQuestionStatusWithOutUpdateTime(ctx context.Contex
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, question.ID)
_ = qr.UpdateSearch(ctx, question.ID)
return nil
}
@@ -175,7 +173,7 @@ func (qr *questionRepo) RecoverQuestion(ctx context.Context, questionID string)
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, questionID)
_ = qr.UpdateSearch(ctx, questionID)
return nil
}
@@ -194,7 +192,7 @@ func (qr *questionRepo) UpdateAccepted(ctx context.Context, question *entity.Que
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, question.ID)
_ = qr.UpdateSearch(ctx, question.ID)
return nil
}
@@ -204,7 +202,7 @@ func (qr *questionRepo) UpdateLastAnswer(ctx context.Context, question *entity.Q
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
_ = qr.updateSearch(ctx, question.ID)
_ = qr.UpdateSearch(ctx, question.ID)
return nil
}
@@ -461,8 +459,8 @@ func (qr *questionRepo) AdminQuestionPage(ctx context.Context, search *schema.Ad
return rows, count, nil
}
// updateSearch update search, if search plugin not enable, do nothing
func (qr *questionRepo) updateSearch(ctx context.Context, questionID string) (err error) {
// UpdateSearch update search, if search plugin not enable, do nothing
func (qr *questionRepo) UpdateSearch(ctx context.Context, questionID string) (err error) {
// check search plugin
var s plugin.Search
_ = plugin.CallSearch(func(search plugin.Search) error {
@@ -543,7 +541,7 @@ func (qr *questionRepo) RemoveAllUserQuestion(ctx context.Context, userID string
// update search content
for _, id := range questionIDs {
_ = qr.updateSearch(ctx, id)
_ = qr.UpdateSearch(ctx, id)
}
return nil
}
@@ -72,6 +72,7 @@ type QuestionRepo interface {
GetUserQuestionCount(ctx context.Context, userID string) (count int64, err error)
SitemapQuestions(ctx context.Context, page, pageSize int) (questionIDList []*schema.SiteMapQuestionInfo, err error)
RemoveAllUserQuestion(ctx context.Context, userID string) (err error)
UpdateSearch(ctx context.Context, questionID string) (err error)
}
// QuestionCommon user service
+1
View File
@@ -314,6 +314,7 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
if err != nil {
return
}
_ = qs.questionRepo.UpdateSearch(ctx, question.ID)
revisionDTO := &schema.AddRevisionDTO{
UserID: question.UserID,