Performance optimization for pull request files loading comments attachments (#33585)

This commit is contained in:
Lunny Xiao 2025-02-13 22:49:58 -08:00 committed by GitHub
parent b426e383fe
commit f232d8f530
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View File

@ -86,8 +86,10 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
ids = append(ids, comment.ReviewID) ids = append(ids, comment.ReviewID)
} }
} }
if err := e.In("id", ids).Find(&reviews); err != nil { if len(ids) > 0 {
return nil, err if err := e.In("id", ids).Find(&reviews); err != nil {
return nil, err
}
} }
n := 0 n := 0

View File

@ -784,18 +784,18 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
return return
} }
allComments := issues_model.CommentList{}
for _, file := range diff.Files { for _, file := range diff.Files {
for _, section := range file.Sections { for _, section := range file.Sections {
for _, line := range section.Lines { for _, line := range section.Lines {
for _, comment := range line.Comments { allComments = append(allComments, line.Comments...)
if err := comment.LoadAttachments(ctx); err != nil {
ctx.ServerError("LoadAttachments", err)
return
}
}
} }
} }
} }
if err := allComments.LoadAttachments(ctx); err != nil {
ctx.ServerError("LoadAttachments", err)
return
}
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch) pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch)
if err != nil { if err != nil {

View File

@ -80,7 +80,7 @@ type DiffLine struct {
Match int Match int
Type DiffLineType Type DiffLineType
Content string Content string
Comments []*issues_model.Comment Comments issues_model.CommentList
SectionInfo *DiffLineSectionInfo SectionInfo *DiffLineSectionInfo
} }