diff options
author | Giteabot <teabot@gitea.io> | 2023-09-29 13:31:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-29 13:31:10 +0800 |
commit | b6b71c78c453c631fe3ea42183a147ff68972fad (patch) | |
tree | 60b79adbb4b9ac9524e5f9f9f4dd7ce4083e4053 /models | |
parent | 2138661dae2fbb88eba1a04d48faf27a2cebb934 (diff) | |
download | gitea-b6b71c78c453c631fe3ea42183a147ff68972fad.tar.gz gitea-b6b71c78c453c631fe3ea42183a147ff68972fad.zip |
Add logs for data broken of comment review (#27326) (#27344)
Backport #27326 by @lunny
Fix #27306
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/issues/comment_list.go | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/models/issues/comment_list.go b/models/issues/comment_list.go index 477337443d..79dcecf2ba 100644 --- a/models/issues/comment_list.go +++ b/models/issues/comment_list.go @@ -10,6 +10,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" + "code.gitea.io/gitea/modules/log" ) // CommentList defines a list of comments @@ -422,37 +423,18 @@ func (comments CommentList) loadReviews(ctx context.Context) error { reviewIDs := comments.getReviewIDs() reviews := make(map[int64]*Review, len(reviewIDs)) - left := len(reviewIDs) - 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 - } - - 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:] + if err := db.GetEngine(ctx).In("id", reviewIDs).Find(&reviews); err != nil { + return err } for _, comment := range comments { 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. // Otherwise, the reviewer is the poster of the comment, so we don't need to load it. |