mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	Backport #27326 by @lunny Fix #27306 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		
					parent
					
						
							
								7ea7f2b37f
							
						
					
				
			
			
				commit
				
					
						f77b4cb4a2
					
				
			
		
					 1 changed files with 9 additions and 27 deletions
				
			
		| 
						 | 
					@ -10,6 +10,7 @@ import (
 | 
				
			||||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
						repo_model "code.gitea.io/gitea/models/repo"
 | 
				
			||||||
	user_model "code.gitea.io/gitea/models/user"
 | 
						user_model "code.gitea.io/gitea/models/user"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/container"
 | 
						"code.gitea.io/gitea/modules/container"
 | 
				
			||||||
 | 
						"code.gitea.io/gitea/modules/log"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CommentList defines a list of comments
 | 
					// CommentList defines a list of comments
 | 
				
			||||||
| 
						 | 
					@ -422,37 +423,18 @@ func (comments CommentList) loadReviews(ctx context.Context) error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	reviewIDs := comments.getReviewIDs()
 | 
						reviewIDs := comments.getReviewIDs()
 | 
				
			||||||
	reviews := make(map[int64]*Review, len(reviewIDs))
 | 
						reviews := make(map[int64]*Review, len(reviewIDs))
 | 
				
			||||||
	left := len(reviewIDs)
 | 
						if err := db.GetEngine(ctx).In("id", reviewIDs).Find(&reviews); err != nil {
 | 
				
			||||||
	for left > 0 {
 | 
					 | 
				
			||||||
		limit := db.DefaultMaxInSize
 | 
					 | 
				
			||||||
		if left < limit {
 | 
					 | 
				
			||||||
			limit = left
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		rows, err := db.GetEngine(ctx).
 | 
					 | 
				
			||||||
			In("id", reviewIDs[:limit]).
 | 
					 | 
				
			||||||
			Rows(new(Review))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for rows.Next() {
 | 
					 | 
				
			||||||
			var review Review
 | 
					 | 
				
			||||||
			err = rows.Scan(&review)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				_ = rows.Close()
 | 
					 | 
				
			||||||
				return err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			reviews[review.ID] = &review
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		_ = rows.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		left -= limit
 | 
					 | 
				
			||||||
		reviewIDs = reviewIDs[limit:]
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, comment := range comments {
 | 
						for _, comment := range comments {
 | 
				
			||||||
		comment.Review = reviews[comment.ReviewID]
 | 
							comment.Review = reviews[comment.ReviewID]
 | 
				
			||||||
 | 
							if comment.Review == nil {
 | 
				
			||||||
 | 
								if comment.ReviewID > 0 {
 | 
				
			||||||
 | 
									log.Error("comment with review id [%d] but has no review record", comment.ReviewID)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// If the comment dismisses a review, we need to load the reviewer to show whose review has been dismissed.
 | 
							// If the comment dismisses a review, we need to load the reviewer to show whose review has been dismissed.
 | 
				
			||||||
		// Otherwise, the reviewer is the poster of the comment, so we don't need to load it.
 | 
							// Otherwise, the reviewer is the poster of the comment, so we don't need to load it.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue