Skip to content

Commit 5e9cc91

Browse files
GiteaBotlunny
andauthored
Performance optimization for pull request files loading comments attachments (#33585) (#33592)
Backport #33585 by @lunny Co-authored-by: Lunny Xiao <[email protected]>
1 parent cc6ec56 commit 5e9cc91

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

models/issues/comment_code.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
8686
ids = append(ids, comment.ReviewID)
8787
}
8888
}
89-
if err := e.In("id", ids).Find(&reviews); err != nil {
90-
return nil, err
89+
if len(ids) > 0 {
90+
if err := e.In("id", ids).Find(&reviews); err != nil {
91+
return nil, err
92+
}
9193
}
9294

9395
n := 0

routers/web/repo/pull.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -785,18 +785,18 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
785785
return
786786
}
787787

788+
allComments := issues_model.CommentList{}
788789
for _, file := range diff.Files {
789790
for _, section := range file.Sections {
790791
for _, line := range section.Lines {
791-
for _, comment := range line.Comments {
792-
if err := comment.LoadAttachments(ctx); err != nil {
793-
ctx.ServerError("LoadAttachments", err)
794-
return
795-
}
796-
}
792+
allComments = append(allComments, line.Comments...)
797793
}
798794
}
799795
}
796+
if err := allComments.LoadAttachments(ctx); err != nil {
797+
ctx.ServerError("LoadAttachments", err)
798+
return
799+
}
800800

801801
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch)
802802
if err != nil {

services/gitdiff/gitdiff.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type DiffLine struct {
8080
Match int
8181
Type DiffLineType
8282
Content string
83-
Comments []*issues_model.Comment
83+
Comments issues_model.CommentList
8484
SectionInfo *DiffLineSectionInfo
8585
}
8686

0 commit comments

Comments
 (0)