diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-03-21 14:13:08 +0100 |
---|---|---|
committer | Earl Warren <contact@earl-warren.org> | 2024-03-26 19:04:26 +0100 |
commit | d92c2048b30c9ca1eab87291ce6e053739db24c6 (patch) | |
tree | e2bc3c473e1419c65c6180e456ce7a1b293f5156 /routers | |
parent | Solving the issue of UI disruption when the review is deleted without refresh... (diff) | |
download | forgejo-d92c2048b30c9ca1eab87291ce6e053739db24c6.tar.xz forgejo-d92c2048b30c9ca1eab87291ce6e053739db24c6.zip |
Performance improvements for pull request list page (#29900)
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
---------
Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 62f8174aa2fae1481c7e17a6afcb731a5b178cd0)
Conflicts:
models/activities/notification_list.go
moved to models/activities/notification.go
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 843da55139..2640819a54 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -874,10 +874,11 @@ func EditIssue(ctx *context.APIContext) { } if form.State != nil { if issue.IsPull { - if pr, err := issue.GetPullRequest(ctx); 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 ff1135862b..8fcf670fd0 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(ctx) - 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 324205ed91..a40c7085ff 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -144,6 +144,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) |