Skip to content

Commit f4ad036

Browse files
committed
Follow yp05327's suggestion
1 parent 29ae51d commit f4ad036

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

models/issues/comment_list.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ import (
1616
// CommentList defines a list of comments
1717
type CommentList []*Comment
1818

19-
func (comments CommentList) getPosterIDs() []int64 {
20-
return container.FilterSlice(comments, func(c *Comment) (int64, bool) {
21-
return c.PosterID, c.PosterID > 0
22-
})
23-
}
24-
2519
// LoadPosters loads posters
2620
func (comments CommentList) LoadPosters(ctx context.Context) error {
2721
if len(comments) == 0 {
2822
return nil
2923
}
3024

31-
posterMaps, err := getPosters(ctx, comments.getPosterIDs())
25+
posterIDs := container.FilterSlice(comments, func(c *Comment) (int64, bool) {
26+
return c.PosterID, c.Poster == nil && c.PosterID > 0
27+
})
28+
29+
posterMaps, err := getPostersByIDs(ctx, posterIDs)
3230
if err != nil {
3331
return err
3432
}

models/issues/issue_list.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,16 @@ func (issues IssueList) LoadRepositories(ctx context.Context) (repo_model.Reposi
7272
return repo_model.ValuesRepository(repoMaps), nil
7373
}
7474

75-
func (issues IssueList) getPosterIDs() []int64 {
76-
return container.FilterSlice(issues, func(issue *Issue) (int64, bool) {
77-
return issue.PosterID, issue.Poster == nil
78-
})
79-
}
80-
8175
func (issues IssueList) LoadPosters(ctx context.Context) error {
8276
if len(issues) == 0 {
8377
return nil
8478
}
8579

86-
posterMaps, err := getPosters(ctx, issues.getPosterIDs())
80+
posterIDs := container.FilterSlice(issues, func(issue *Issue) (int64, bool) {
81+
return issue.PosterID, issue.Poster == nil && issue.PosterID > 0
82+
})
83+
84+
posterMaps, err := getPostersByIDs(ctx, posterIDs)
8785
if err != nil {
8886
return err
8987
}
@@ -94,7 +92,7 @@ func (issues IssueList) LoadPosters(ctx context.Context) error {
9492
return nil
9593
}
9694

97-
func getPosters(ctx context.Context, posterIDs []int64) (map[int64]*user_model.User, error) {
95+
func getPostersByIDs(ctx context.Context, posterIDs []int64) (map[int64]*user_model.User, error) {
9896
posterMaps := make(map[int64]*user_model.User, len(posterIDs))
9997
left := len(posterIDs)
10098
for left > 0 {

services/convert/issue.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ func ToAPIIssue(ctx context.Context, doer *user_model.User, issue *issues_model.
3131
}
3232

3333
func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, getDownloadURL func(repo *repo_model.Repository, attach *repo_model.Attachment) string) *api.Issue {
34-
if err := issue.LoadLabels(ctx); err != nil {
35-
return &api.Issue{}
36-
}
3734
if err := issue.LoadPoster(ctx); err != nil {
3835
return &api.Issue{}
3936
}
@@ -66,6 +63,9 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
6663
}
6764
apiIssue.URL = issue.APIURL(ctx)
6865
apiIssue.HTMLURL = issue.HTMLURL()
66+
if err := issue.LoadLabels(ctx); err != nil {
67+
return &api.Issue{}
68+
}
6969
apiIssue.Labels = ToLabelList(issue.Labels, issue.Repo, issue.Repo.Owner)
7070
apiIssue.Repo = &api.RepositoryMeta{
7171
ID: issue.Repo.ID,

0 commit comments

Comments
 (0)