mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-08 02:31:36 +02:00
Move implementation into db.Tx function
As per the review comments, we are moving the initial implementation into the db.Tx function to ensure that all database code is run or not run. Also make sure any errors are returned first before running the database queries.
This commit is contained in:
parent
4c7572150b
commit
125251aa5c
1 changed files with 18 additions and 15 deletions
|
@ -118,12 +118,27 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion
|
|||
|
||||
// DeleteComment deletes the comment
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) error {
|
||||
reviewID := comment.ReviewID
|
||||
reviewType := comment.Review.Type
|
||||
|
||||
err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
reviewID := comment.ReviewID
|
||||
reviewType := comment.Review.Type
|
||||
|
||||
if reviewType == issues_model.ReviewTypePending {
|
||||
found, err := db.GetEngine(ctx).Table("comment").Where("review_id = ?", reviewID).Exist()
|
||||
if err != nil {
|
||||
return err
|
||||
} else if found {
|
||||
_, err := db.GetEngine(ctx).Table("review").Where("id = ?", reviewID).Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return issues_model.DeleteComment(ctx, comment)
|
||||
}
|
||||
}
|
||||
|
||||
return issues_model.DeleteComment(ctx, comment)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -135,17 +150,5 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m
|
|||
notify_service.DeleteComment(ctx, doer, comment)
|
||||
}
|
||||
|
||||
if reviewType == issues_model.ReviewTypePending {
|
||||
found, err := db.GetEngine(ctx).Table("comment").Where("review_id = ?", reviewID).Exist()
|
||||
if found {
|
||||
_, err := db.GetEngine(ctx).Table("comment").Where("reviewID = ?", reviewID).Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue