diff --git a/models/issues/comment_list.go b/models/issues/comment_list.go index f0baa98dce..0411d44531 100644 --- a/models/issues/comment_list.go +++ b/models/issues/comment_list.go @@ -35,16 +35,7 @@ func (comments CommentList) LoadPosters(ctx context.Context) error { } for _, comment := range comments { - if comment.PosterID == user_model.ActionsUserID { - comment.Poster = user_model.NewActionsUser() - } else if comment.PosterID <= 0 { - continue - } else { - var ok bool - if comment.Poster, ok = posterMaps[comment.PosterID]; !ok { - comment.Poster = user_model.NewGhostUser() - } - } + comment.Poster = getPoster(comment.PosterID, posterMaps) } return nil } diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 4c44bc4832..6ddadd27ed 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -92,16 +92,7 @@ func (issues IssueList) loadPosters(ctx context.Context) error { } for _, issue := range issues { - if issue.PosterID == user_model.ActionsUserID { - issue.Poster = user_model.NewActionsUser() - } else if issue.PosterID <= 0 { - continue - } else { - var ok bool - if issue.Poster, ok = posterMaps[issue.PosterID]; !ok { - issue.Poster = user_model.NewGhostUser() - } - } + issue.Poster = getPoster(issue.PosterID, posterMaps) } return nil } @@ -126,6 +117,20 @@ func getPosters(ctx context.Context, posterIDs []int64) (map[int64]*user_model.U return posterMaps, nil } +func getPoster(posterID int64, posterMaps map[int64]*user_model.User) *user_model.User { + if posterID == user_model.ActionsUserID { + return user_model.NewActionsUser() + } + if posterID <= 0 { + return nil + } + poster, ok := posterMaps[posterID] + if !ok { + return user_model.NewGhostUser() + } + return poster +} + func (issues IssueList) getIssueIDs() []int64 { ids := make([]int64, 0, len(issues)) for _, issue := range issues {