Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of dashboard #4977

Merged
merged 10 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix bugs
  • Loading branch information
lunny committed Nov 30, 2018
commit 597610c7f6e27d749191c5b6dfc463dff4fdf476
10 changes: 9 additions & 1 deletion models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "#"
}
Expand All @@ -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()
}

Expand Down
5 changes: 5 additions & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func (issue *Issue) IsOverdue() bool {
return util.TimeStampNow() >= issue.DeadlineUnix
}

// LoadRepo loads issue's repository
func (issue *Issue) LoadRepo() error {
return issue.loadRepo(x)
}

func (issue *Issue) loadRepo(e Engine) (err error) {
if issue.Repo == nil {
issue.Repo, err = getRepositoryByID(e, issue.RepoID)
Expand Down
22 changes: 22 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func (c *Comment) HTMLURL() string {
log.Error(4, "LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.loadRepo(x)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
if c.Type == CommentTypeCode {
if c.ReviewID == 0 {
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
Expand Down Expand Up @@ -198,6 +203,12 @@ func (c *Comment) IssueURL() string {
if c.Issue.IsPull {
return ""
}

err = c.Issue.loadRepo(x)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
return c.Issue.HTMLURL()
}

Expand All @@ -209,6 +220,12 @@ func (c *Comment) PRURL() string {
return ""
}

err = c.Issue.loadRepo(x)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}

if !c.Issue.IsPull {
return ""
}
Expand Down Expand Up @@ -470,6 +487,11 @@ func (c *Comment) CodeCommentURL() string {
log.Error(4, "LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.loadRepo(x)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
}

Expand Down
2 changes: 1 addition & 1 deletion models/issue_mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content

// In case the issue poster is not watching the repository and is active,
// even if we have duplicated in watchers, can be safely filtered out.
poster, err := GetUserByID(issue.PosterID)
poster, err := getUserByID(e, issue.PosterID)
if err != nil {
return fmt.Errorf("GetUserByID [%d]: %v", issue.PosterID, err)
}
Expand Down
1 change: 1 addition & 0 deletions models/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func composeTplData(subject, body, link string) map[string]interface{} {

func composeIssueCommentMessage(issue *Issue, doer *User, content string, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message {
subject := issue.mailSubject()
issue.LoadRepo()
body := string(markup.RenderByType(markdown.MarkupName, []byte(content), issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))

data := make(map[string]interface{}, 10)
Expand Down
4 changes: 4 additions & 0 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("GetIssueByID", err)
return
}
if err = otherIssue.LoadRepo(); err != nil {
ctx.ServerError("LoadRepo", err)
return
}
// Add link to the issue of the already running stopwatch
ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
}
Expand Down