diff options
Diffstat (limited to 'models/topic.go')
-rw-r--r-- | models/topic.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/models/topic.go b/models/topic.go index 6eb8c67b8d..79c47e2331 100644 --- a/models/topic.go +++ b/models/topic.go @@ -225,11 +225,12 @@ func getRepoTopicByName(e db.Engine, repoID int64, topicName string) (*Topic, er // AddTopic adds a topic name to a repository (if it does not already have it) func AddTopic(repoID int64, topicName string) (*Topic, error) { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return nil, err } + defer committer.Close() + sess := db.GetEngine(ctx) topic, err := getRepoTopicByName(sess, repoID, topicName) if err != nil { @@ -258,7 +259,7 @@ func AddTopic(repoID int64, topicName string) (*Topic, error) { return nil, err } - return topic, sess.Commit() + return topic, committer.Commit() } // DeleteTopic removes a topic name from a repository (if it has it) @@ -286,12 +287,12 @@ func SaveTopics(repoID int64, topicNames ...string) error { return err } - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + sess := db.GetEngine(ctx) var addedTopicNames []string for _, topicName := range topicNames { @@ -352,5 +353,5 @@ func SaveTopics(repoID int64, topicNames ...string) error { return err } - return sess.Commit() + return committer.Commit() } |