From 6151e69d9509c08e25e93743d6b31211371e81d0 Mon Sep 17 00:00:00 2001 From: caicandong <50507092+CaiCandong@users.noreply.github.com> Date: Fri, 4 Aug 2023 21:34:34 +0800 Subject: Delete `issue_service.CreateComment` (#26298) I noticed that `issue_service.CreateComment` adds transaction operations on `issues_model.CreateComment`, we can merge the two functions and we can avoid calling each other's methods in the `services` layer. Co-authored-by: Giteabot --- models/issues/comment.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'models') diff --git a/models/issues/comment.go b/models/issues/comment.go index be020b2e1f..e781931261 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -777,6 +777,12 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) { // CreateComment creates comment with context func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) { + ctx, committer, err := db.TxContext(ctx) + if err != nil { + return nil, err + } + defer committer.Close() + e := db.GetEngine(ctx) var LabelID int64 if opts.Label != nil { @@ -832,7 +838,9 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, if err = comment.AddCrossReferences(ctx, opts.Doer, false); err != nil { return nil, err } - + if err = committer.Commit(); err != nil { + return nil, err + } return comment, nil } -- cgit v1.2.3