From 703c80ee2c2363afe5d3508868ccdb5cca28ce0d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 13 Feb 2024 09:45:31 +0100 Subject: [PATCH] Dont load Review if Comment is CommentTypeReviewRequest (#28551) RequestReview get deleted on review. So we don't have to try to load them on comments. broken out #28544 --- models/issues/comment.go | 7 +++++++ models/issues/comment_list.go | 3 ++- models/issues/review.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index f038d75eb3323..8ee4e9acd6fb3 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -688,8 +688,15 @@ func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository } func (c *Comment) loadReview(ctx context.Context) (err error) { + if c.ReviewID == 0 { + return nil + } if c.Review == nil { if c.Review, err = GetReviewByID(ctx, c.ReviewID); err != nil { + // review request which has been replaced by actual reviews doesn't exist in database anymore, so ignorem them. + if c.Type == CommentTypeReviewRequest { + return nil + } return err } } diff --git a/models/issues/comment_list.go b/models/issues/comment_list.go index 93af45870ed69..cb7df3270d6ad 100644 --- a/models/issues/comment_list.go +++ b/models/issues/comment_list.go @@ -430,7 +430,8 @@ func (comments CommentList) loadReviews(ctx context.Context) error { for _, comment := range comments { comment.Review = reviews[comment.ReviewID] if comment.Review == nil { - if comment.ReviewID > 0 { + // review request which has been replaced by actual reviews doesn't exist in database anymore, so don't log errors for them. + if comment.ReviewID > 0 && comment.Type != CommentTypeReviewRequest { log.Error("comment with review id [%d] but has no review record", comment.ReviewID) } continue diff --git a/models/issues/review.go b/models/issues/review.go index eae8c20e97a71..5bfb8b9dd2242 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -622,6 +622,9 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo return nil, err } + // func caller use the created comment to retrieve created review too. + comment.Review = review + return comment, committer.Commit() }