aboutsummaryrefslogtreecommitdiff
path: root/routers
diff options
context:
space:
mode:
authorzeripath2023-02-27 18:46:00 +0000
committerGitHub2023-02-27 13:46:00 -0500
commitef4fc302468cc8a9fd8f65c4ebdc6f55138450d1 (patch)
treef804073879320d5d0f15d19cbb36d4f7c2a03392 /routers
parent0e7bec1849d2d7a87713abe494b4d3ef416180d4 (diff)
Speed up HasUserStopwatch & GetActiveStopwatch (#23051)
GetActiveStopwatch & HasUserStopwatch is a hot piece of code that is repeatedly called and on examination of the cpu profile for TestGit it represents 0.44 seconds of CPU time. This PR reduces this time to 80ms. --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: delvh <leon@kske.dev>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/issue.go15
-rw-r--r--routers/web/repo/issue_stopwatch.go14
2 files changed, 4 insertions, 25 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 745d6e70a..e4f940061 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -1432,25 +1432,16 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["IsStopwatchRunning"] = issues_model.StopwatchExists(ctx.Doer.ID, issue.ID)
if !ctx.Data["IsStopwatchRunning"].(bool) {
var exists bool
- var sw *issues_model.Stopwatch
- if exists, sw, err = issues_model.HasUserStopwatch(ctx, ctx.Doer.ID); err != nil {
+ var swIssue *issues_model.Issue
+ if exists, _, swIssue, err = issues_model.HasUserStopwatch(ctx, ctx.Doer.ID); err != nil {
ctx.ServerError("HasUserStopwatch", err)
return
}
ctx.Data["HasUserStopwatch"] = exists
if exists {
// Add warning if the user has already a stopwatch
- var otherIssue *issues_model.Issue
- if otherIssue, err = issues_model.GetIssueByID(ctx, sw.IssueID); err != nil {
- ctx.ServerError("GetIssueByID", err)
- return
- }
- if err = otherIssue.LoadRepo(ctx); err != nil {
- ctx.ServerError("LoadRepo", err)
- return
- }
// Add link to the issue of the already running stopwatch
- ctx.Data["OtherStopwatchURL"] = otherIssue.Link()
+ ctx.Data["OtherStopwatchURL"] = swIssue.Link()
}
}
ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.Doer)
diff --git a/routers/web/repo/issue_stopwatch.go b/routers/web/repo/issue_stopwatch.go
index 3d20b08b4..3e715437e 100644
--- a/routers/web/repo/issue_stopwatch.go
+++ b/routers/web/repo/issue_stopwatch.go
@@ -86,7 +86,7 @@ func GetActiveStopwatch(ctx *context.Context) {
return
}
- _, sw, err := issues_model.HasUserStopwatch(ctx, ctx.Doer.ID)
+ _, sw, issue, err := issues_model.HasUserStopwatch(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("HasUserStopwatch", err)
return
@@ -96,18 +96,6 @@ func GetActiveStopwatch(ctx *context.Context) {
return
}
- issue, err := issues_model.GetIssueByID(ctx, sw.IssueID)
- if err != nil || issue == nil {
- if !issues_model.IsErrIssueNotExist(err) {
- ctx.ServerError("GetIssueByID", err)
- }
- return
- }
- if err = issue.LoadRepo(ctx); err != nil {
- ctx.ServerError("LoadRepo", err)
- return
- }
-
ctx.Data["ActiveStopwatch"] = StopwatchTmplInfo{
issue.Link(),
issue.Repo.FullName(),