mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Fetch all review ids at once
Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
@@ -802,17 +802,30 @@ func fetchCodeComments(e Engine, issue *Issue, currentUser *User) (map[string]ma
|
||||
if err = issue.loadRepo(e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Find all reviews by ReviewID
|
||||
reviews := make(map[int64]*Review)
|
||||
var ids = make([]int64, 0, len(comments))
|
||||
for _, comment := range comments {
|
||||
if err = comment.loadReview(e); err != nil && !IsErrReviewNotExist(err) {
|
||||
return nil, err
|
||||
if comment.ReviewID != 0 {
|
||||
ids = append(ids, comment.ReviewID)
|
||||
}
|
||||
if comment.Review != nil && comment.Review.Type == ReviewTypePending {
|
||||
if currentUser == nil || currentUser.ID != comment.Review.ReviewerID {
|
||||
continue
|
||||
}
|
||||
if err = e.In("id", ids).Find(&reviews); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, comment := range comments {
|
||||
if re, ok := reviews[comment.ReviewID]; ok && re != nil {
|
||||
// If the review is pending only the author can see the comments
|
||||
if re.Type == ReviewTypePending &&
|
||||
(currentUser == nil || currentUser.ID != re.ReviewerID) {
|
||||
continue
|
||||
}
|
||||
comment.Review = re
|
||||
}
|
||||
|
||||
comment.RenderedContent = string(markdown.Render([]byte(comment.Content), issue.Repo.Link(),
|
||||
issue.Repo.ComposeMetas()))
|
||||
|
||||
if pathToLineToComment[comment.TreePath] == nil {
|
||||
pathToLineToComment[comment.TreePath] = make(map[int64][]*Comment)
|
||||
}
|
||||
|
Reference in New Issue
Block a user