|
@@ -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
|
+} |