diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-03-22 09:58:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 09:58:04 +0800 |
commit | 6ef986d47452f36b101edc3cc9e3c41ad480eb09 (patch) | |
tree | a1e60a11e93d5696481a808fcbce07d4229951e4 /routers | |
parent | c03b1e28544ee60c72f9dc7d9f362753bb3d778c (diff) | |
download | gitea-6ef986d47452f36b101edc3cc9e3c41ad480eb09.tar.gz gitea-6ef986d47452f36b101edc3cc9e3c41ad480eb09.zip |
Performance improvements for pull request list page (#29900) (#29972)
This PR will avoid load pullrequest.Issue twice in pull request list
page. It will reduce x times database queries for those WIP pull
requests.
Partially fix #29585
Backport #29900
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_pin.go | 16 | ||||
-rw-r--r-- | routers/web/user/notification.go | 6 |
3 files changed, 14 insertions, 13 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index fe9a491603..8c502467fd 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -864,10 +864,11 @@ func EditIssue(ctx *context.APIContext) { } if form.State != nil { if issue.IsPull { - if pr, err := issue.GetPullRequest(); err != nil { + if err := issue.LoadPullRequest(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "GetPullRequest", err) return - } else if pr.HasMerged { + } + if issue.PullRequest.HasMerged { ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged") return } diff --git a/routers/api/v1/repo/issue_pin.go b/routers/api/v1/repo/issue_pin.go index d9b1bcc894..9bd609fcac 100644 --- a/routers/api/v1/repo/issue_pin.go +++ b/routers/api/v1/repo/issue_pin.go @@ -240,18 +240,12 @@ func ListPinnedPullRequests(ctx *context.APIContext) { } apiPrs := make([]*api.PullRequest, len(issues)) + if err := issues.LoadPullRequests(ctx); err != nil { + ctx.Error(http.StatusInternalServerError, "LoadPullRequests", err) + return + } for i, currentIssue := range issues { - pr, err := currentIssue.GetPullRequest() - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetPullRequest", err) - return - } - - if err = pr.LoadIssue(ctx); err != nil { - ctx.Error(http.StatusInternalServerError, "LoadIssue", err) - return - } - + pr := currentIssue.PullRequest if err = pr.LoadAttributes(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "LoadAttributes", err) return diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 579287ffac..6fa7a0bb09 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -128,6 +128,12 @@ func getNotifications(ctx *context.Context) { ctx.ServerError("LoadIssues", err) return } + + if err = notifications.LoadIssuePullRequests(ctx); err != nil { + ctx.ServerError("LoadIssuePullRequests", err) + return + } + notifications = notifications.Without(failures) failCount += len(failures) |