diff --git a/internal/dao/search_zinc.go b/internal/dao/search_zinc.go index debae521..dc3630a5 100644 --- a/internal/dao/search_zinc.go +++ b/internal/dao/search_zinc.go @@ -49,7 +49,7 @@ func (s *zincTweetSearchServant) AddDocuments(data core.DocItems, primaryKey ... }) } buf = append(buf, data...) - return s.client.BulkPushDoc(data) + return s.client.BulkPushDoc(buf) } func (s *zincTweetSearchServant) DeleteDocuments(identifiers []string) error { diff --git a/internal/service/post.go b/internal/service/post.go index 35ac6764..c9f21313 100644 --- a/internal/service/post.go +++ b/internal/service/post.go @@ -12,9 +12,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/model" "github.com/rocboss/paopao-ce/pkg/errcode" - "github.com/rocboss/paopao-ce/pkg/json" "github.com/rocboss/paopao-ce/pkg/util" - "github.com/rocboss/paopao-ce/pkg/zinc" "github.com/sirupsen/logrus" ) @@ -430,47 +428,7 @@ func GetPostList(req *PostListReq) ([]*model.PostFormated, error) { return nil, err } - return FormatPosts(posts) -} - -func FormatPosts(posts []*model.Post) ([]*model.PostFormated, error) { - postIds := []int64{} - userIds := []int64{} - for _, post := range posts { - postIds = append(postIds, post.ID) - userIds = append(userIds, post.UserID) - } - - postContents, err := ds.GetPostContentsByIDs(postIds) - if err != nil { - return nil, err - } - - users, err := ds.GetUsersByIDs(userIds) - if err != nil { - return nil, err - } - - // 数据整合 - postsFormated := []*model.PostFormated{} - for _, post := range posts { - postFormated := post.Format() - - for _, user := range users { - if user.ID == postFormated.UserID { - postFormated.User = user.Format() - } - } - for _, content := range postContents { - if content.PostID == post.ID { - postFormated.Contents = append(postFormated.Contents, content.Format()) - } - } - - postsFormated = append(postsFormated, postFormated) - } - - return postsFormated, nil + return ds.MergePosts(posts) } func GetPostCount(conditions *model.ConditionsT) (int64, error) { @@ -603,54 +561,6 @@ func PushPostsToSearch(c *gin.Context) { } } -func FormatZincPost(queryResult *zinc.QueryResultT) ([]*model.PostFormated, error) { - posts := []*model.PostFormated{} - for _, hit := range queryResult.Hits.Hits { - item := &model.PostFormated{} - - raw, _ := json.Marshal(hit.Source) - err := json.Unmarshal(raw, item) - if err == nil { - posts = append(posts, item) - } - } - - postIds := []int64{} - userIds := []int64{} - for _, post := range posts { - postIds = append(postIds, post.ID) - userIds = append(userIds, post.UserID) - } - postContents, err := ds.GetPostContentsByIDs(postIds) - if err != nil { - return nil, err - } - - users, err := ds.GetUsersByIDs(userIds) - if err != nil { - return nil, err - } - - // 数据整合 - for _, post := range posts { - for _, user := range users { - if user.ID == post.UserID { - post.User = user.Format() - } - } - if post.Contents == nil { - post.Contents = []*model.PostContentFormated{} - } - for _, content := range postContents { - if content.PostID == post.ID { - post.Contents = append(post.Contents, content.Format()) - } - } - } - - return posts, nil -} - func GetPostTags(param *PostTagsReq) ([]*model.TagFormated, error) { num := param.Num if num > conf.AppSetting.MaxPageSize {