Skip to content

Commit b6b71c7

Browse files
GiteaBotlunny
andauthored
Add logs for data broken of comment review (#27326) (#27344)
Backport #27326 by @lunny Fix #27306 Co-authored-by: Lunny Xiao <[email protected]>
1 parent 2138661 commit b6b71c7

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

models/issues/comment_list.go

+9-27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
repo_model "code.gitea.io/gitea/models/repo"
1111
user_model "code.gitea.io/gitea/models/user"
1212
"code.gitea.io/gitea/modules/container"
13+
"code.gitea.io/gitea/modules/log"
1314
)
1415

1516
// CommentList defines a list of comments
@@ -422,37 +423,18 @@ func (comments CommentList) loadReviews(ctx context.Context) error {
422423

423424
reviewIDs := comments.getReviewIDs()
424425
reviews := make(map[int64]*Review, len(reviewIDs))
425-
left := len(reviewIDs)
426-
for left > 0 {
427-
limit := db.DefaultMaxInSize
428-
if left < limit {
429-
limit = left
430-
}
431-
rows, err := db.GetEngine(ctx).
432-
In("id", reviewIDs[:limit]).
433-
Rows(new(Review))
434-
if err != nil {
435-
return err
436-
}
437-
438-
for rows.Next() {
439-
var review Review
440-
err = rows.Scan(&review)
441-
if err != nil {
442-
_ = rows.Close()
443-
return err
444-
}
445-
446-
reviews[review.ID] = &review
447-
}
448-
_ = rows.Close()
449-
450-
left -= limit
451-
reviewIDs = reviewIDs[limit:]
426+
if err := db.GetEngine(ctx).In("id", reviewIDs).Find(&reviews); err != nil {
427+
return err
452428
}
453429

454430
for _, comment := range comments {
455431
comment.Review = reviews[comment.ReviewID]
432+
if comment.Review == nil {
433+
if comment.ReviewID > 0 {
434+
log.Error("comment with review id [%d] but has no review record", comment.ReviewID)
435+
}
436+
continue
437+
}
456438

457439
// If the comment dismisses a review, we need to load the reviewer to show whose review has been dismissed.
458440
// Otherwise, the reviewer is the poster of the comment, so we don't need to load it.

0 commit comments

Comments
 (0)