1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-03 09:07:19 +00:00

Improve performance of dashboard (#4977)

This commit is contained in:
Lunny Xiao
2018-12-13 23:55:43 +08:00
committed by techknowlogick
parent 49ea6e0deb
commit b3b7598ec6
19 changed files with 350 additions and 94 deletions

View File

@ -194,6 +194,10 @@ func (a *Action) GetRepoLink() string {
// GetCommentLink returns link to action comment.
func (a *Action) GetCommentLink() string {
return a.getCommentLink(x)
}
func (a *Action) getCommentLink(e Engine) string {
if a == nil {
return "#"
}
@ -213,11 +217,15 @@ func (a *Action) GetCommentLink() string {
return "#"
}
issue, err := GetIssueByID(issueID)
issue, err := getIssueByID(e, issueID)
if err != nil {
return "#"
}
if err = issue.loadRepo(e); err != nil {
return "#"
}
return issue.HTMLURL()
}
@ -330,13 +338,15 @@ type PushCommits struct {
Commits []*PushCommit
CompareURL string
avatars map[string]string
avatars map[string]string
emailUsers map[string]*User
}
// NewPushCommits creates a new PushCommits object.
func NewPushCommits() *PushCommits {
return &PushCommits{
avatars: make(map[string]string),
avatars: make(map[string]string),
emailUsers: make(map[string]*User),
}
}
@ -344,16 +354,34 @@ func NewPushCommits() *PushCommits {
// api.PayloadCommit format.
func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit {
commits := make([]*api.PayloadCommit, len(pc.Commits))
if pc.emailUsers == nil {
pc.emailUsers = make(map[string]*User)
}
var err error
for i, commit := range pc.Commits {
authorUsername := ""
author, err := GetUserByEmail(commit.AuthorEmail)
if err == nil {
author, ok := pc.emailUsers[commit.AuthorEmail]
if !ok {
author, err = GetUserByEmail(commit.AuthorEmail)
if err == nil {
authorUsername = author.Name
pc.emailUsers[commit.AuthorEmail] = author
}
} else {
authorUsername = author.Name
}
committerUsername := ""
committer, err := GetUserByEmail(commit.CommitterEmail)
if err == nil {
// TODO: check errors other than email not found.
committer, ok := pc.emailUsers[commit.CommitterEmail]
if !ok {
committer, err = GetUserByEmail(commit.CommitterEmail)
if err == nil {
// TODO: check errors other than email not found.
committerUsername = committer.Name
pc.emailUsers[commit.CommitterEmail] = committer
}
} else {
committerUsername = committer.Name
}
commits[i] = &api.PayloadCommit{
@ -379,18 +407,28 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit
// AvatarLink tries to match user in database with e-mail
// in order to show custom avatar, and falls back to general avatar link.
func (pc *PushCommits) AvatarLink(email string) string {
_, ok := pc.avatars[email]
avatar, ok := pc.avatars[email]
if ok {
return avatar
}
u, ok := pc.emailUsers[email]
if !ok {
u, err := GetUserByEmail(email)
var err error
u, err = GetUserByEmail(email)
if err != nil {
pc.avatars[email] = base.AvatarLink(email)
if !IsErrUserNotExist(err) {
log.Error(4, "GetUserByEmail: %v", err)
return ""
}
} else {
pc.avatars[email] = u.RelAvatarLink()
pc.emailUsers[email] = u
}
}
if u != nil {
pc.avatars[email] = u.RelAvatarLink()
}
return pc.avatars[email]
}
@ -479,7 +517,8 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
continue
}
if err = issue.ChangeStatus(doer, repo, true); err != nil {
issue.Repo = repo
if err = issue.ChangeStatus(doer, true); err != nil {
// Don't return an error when dependencies are open as this would let the push fail
if IsErrDependenciesLeft(err) {
return nil
@ -504,7 +543,8 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
continue
}
if err = issue.ChangeStatus(doer, repo, false); err != nil {
issue.Repo = repo
if err = issue.ChangeStatus(doer, false); err != nil {
return err
}
}