Skip to content

Commit f232d8f

Browse files
authored
Performance optimization for pull request files loading comments attachments (#33585)
1 parent b426e38 commit f232d8f

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
@@ -784,18 +784,18 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
784784
return
785785
}
786786

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

800800
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch)
801801
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)