作者 tangxvhui

调整 文章搜索结果中作者展示的数据

@@ -544,6 +544,7 @@ type ( @@ -544,6 +544,7 @@ type (
544 MiniSearchArticleItem{ 544 MiniSearchArticleItem{
545 ArticleId int64 `json:"articleId"` 545 ArticleId int64 `json:"articleId"`
546 Title string `json:"title"` 546 Title string `json:"title"`
  547 + AuthorId int64 `json:"authorId"`
547 Author string `json:"author"` // 发布人 548 Author string `json:"author"` // 发布人
548 Avatar string `json:"avatar"`// 发布人的头像 549 Avatar string `json:"avatar"`// 发布人的头像
549 Images []string `json:"images"` 550 Images []string `json:"images"`
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 5
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
10 11
@@ -13,8 +14,9 @@ import ( @@ -13,8 +14,9 @@ import (
13 14
14 type MiniSearchArticlePageLogic struct { 15 type MiniSearchArticlePageLogic struct {
15 logx.Logger 16 logx.Logger
16 - ctx context.Context  
17 - svcCtx *svc.ServiceContext 17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 + userCache map[int64]*domain.User
18 } 20 }
19 21
20 func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic { 22 func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic {
@@ -63,11 +65,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch @@ -63,11 +65,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
63 } 65 }
64 66
65 for i, val := range articleList { 67 for i, val := range articleList {
  68 + author := l.getAuthor(conn, val.AuthorId)
66 item := types.MiniSearchArticleItem{ 69 item := types.MiniSearchArticleItem{
67 ArticleId: val.Id, 70 ArticleId: val.Id,
68 Title: val.Title, 71 Title: val.Title,
69 - Author: val.Author.Name,  
70 - Avatar: val.Author.Avatar, 72 + AuthorId: val.AuthorId,
  73 + Author: author.Name,
  74 + Avatar: author.Avatar,
71 Images: []string{}, 75 Images: []string{},
72 CreatedAt: val.CreatedAt, 76 CreatedAt: val.CreatedAt,
73 MeReadFlag: 0, 77 MeReadFlag: 0,
@@ -84,3 +88,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch @@ -84,3 +88,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
84 88
85 return resp, nil 89 return resp, nil
86 } 90 }
  91 +
  92 +func (l *MiniSearchArticlePageLogic) getAuthor(conn transaction.Conn, userid int64) domain.User {
  93 + if u, ok := l.userCache[userid]; ok {
  94 + return *u
  95 + }
  96 + toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
  97 + if err == nil {
  98 + l.userCache[toUser.Id] = toUser
  99 + return *toUser
  100 + }
  101 + return domain.User{}
  102 +}
@@ -1315,6 +1315,7 @@ type MiniSearchArticleResponse struct { @@ -1315,6 +1315,7 @@ type MiniSearchArticleResponse struct {
1315 type MiniSearchArticleItem struct { 1315 type MiniSearchArticleItem struct {
1316 ArticleId int64 `json:"articleId"` 1316 ArticleId int64 `json:"articleId"`
1317 Title string `json:"title"` 1317 Title string `json:"title"`
  1318 + AuthorId int64 `json:"authorId"`
1318 Author string `json:"author"` // 发布人 1319 Author string `json:"author"` // 发布人
1319 Avatar string `json:"avatar"` // 发布人的头像 1320 Avatar string `json:"avatar"` // 发布人的头像
1320 Images []string `json:"images"` 1321 Images []string `json:"images"`