From 8a1baf60bf52d26ee683eb07515e9435ac81d908 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 13 Feb 2025 12:06:37 -0800 Subject: [PATCH 1/3] Performance optimization for pull request files loading comments attachments --- routers/web/repo/pull.go | 8 +++----- services/gitdiff/gitdiff.go | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index e6fb492d6e370..9f80b453cf60a 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -787,11 +787,9 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi for _, file := range diff.Files { for _, section := range file.Sections { for _, line := range section.Lines { - for _, comment := range line.Comments { - if err := comment.LoadAttachments(ctx); err != nil { - ctx.ServerError("LoadAttachments", err) - return - } + if err := line.Comments.LoadAttachments(ctx); err != nil { + ctx.ServerError("LoadAttachments", err) + return } } } diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index f046e596782f0..064f05cfce9f7 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -80,7 +80,7 @@ type DiffLine struct { Match int Type DiffLineType Content string - Comments []*issues_model.Comment + Comments issues_model.CommentList SectionInfo *DiffLineSectionInfo } From 13ee43a6ba311fda2dab36a8b56266f3432f7a6c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 13 Feb 2025 12:15:17 -0800 Subject: [PATCH 2/3] A small optimization to load empty reviews --- models/issues/comment_code.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go index 67a77ceb13f36..b562aab5005f6 100644 --- a/models/issues/comment_code.go +++ b/models/issues/comment_code.go @@ -86,8 +86,10 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu ids = append(ids, comment.ReviewID) } } - if err := e.In("id", ids).Find(&reviews); err != nil { - return nil, err + if len(ids) > 0 { + if err := e.In("id", ids).Find(&reviews); err != nil { + return nil, err + } } n := 0 From 40377f322bbe6f3480d8cb834c2443e7fb12eafd Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 13 Feb 2025 14:51:18 -0800 Subject: [PATCH 3/3] improvements --- routers/web/repo/pull.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 9f80b453cf60a..0c82736eefcfd 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -784,16 +784,18 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi return } + allComments := issues_model.CommentList{} for _, file := range diff.Files { for _, section := range file.Sections { for _, line := range section.Lines { - if err := line.Comments.LoadAttachments(ctx); err != nil { - ctx.ServerError("LoadAttachments", err) - return - } + allComments = append(allComments, line.Comments...) } } } + if err := allComments.LoadAttachments(ctx); err != nil { + ctx.ServerError("LoadAttachments", err) + return + } pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch) if err != nil {