summaryrefslogtreecommitdiffstats
path: root/models/topic.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-09-23 16:45:36 +0100
committerGitHub <noreply@github.com>2021-09-23 23:45:36 +0800
commit9302eba971611601c3ebf6024e22a11c63f4e151 (patch)
treea3e5583986161ef62e7affc694098279ecf2217d /models/topic.go
parentb22be7f594401d7bd81196750456ce52185bd391 (diff)
downloadgitea-9302eba971611601c3ebf6024e22a11c63f4e151.tar.gz
gitea-9302eba971611601c3ebf6024e22a11c63f4e151.zip
DBContext is just a Context (#17100)
* DBContext is just a Context This PR removes some of the specialness from the DBContext and makes it context This allows us to simplify the GetEngine code to wrap around any context in future and means that we can change our loadRepo(e Engine) functions to simply take contexts. Signed-off-by: Andrew Thornton <art27@cantab.net> * fix unit tests Signed-off-by: Andrew Thornton <art27@cantab.net> * another place that needs to set the initial context Signed-off-by: Andrew Thornton <art27@cantab.net> * avoid race Signed-off-by: Andrew Thornton <art27@cantab.net> * change attachment error Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models/topic.go')
-rw-r--r--models/topic.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/models/topic.go b/models/topic.go
index 4b219cc0eb..cf563e9b11 100644
--- a/models/topic.go
+++ b/models/topic.go
@@ -88,7 +88,7 @@ func SanitizeAndValidateTopics(topics []string) (validTopics, invalidTopics []st
// GetTopicByName retrieves topic by name
func GetTopicByName(name string) (*Topic, error) {
var topic Topic
- if has, err := db.DefaultContext().Engine().Where("name = ?", name).Get(&topic); err != nil {
+ if has, err := db.GetEngine(db.DefaultContext).Where("name = ?", name).Get(&topic); err != nil {
return nil, err
} else if !has {
return nil, ErrTopicNotExist{name}
@@ -184,7 +184,7 @@ func (opts *FindTopicOptions) toConds() builder.Cond {
// FindTopics retrieves the topics via FindTopicOptions
func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) {
- sess := db.DefaultContext().Engine().Select("topic.*").Where(opts.toConds())
+ sess := db.GetEngine(db.DefaultContext).Select("topic.*").Where(opts.toConds())
if opts.RepoID > 0 {
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
}
@@ -198,7 +198,7 @@ func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) {
// CountTopics counts the number of topics matching the FindTopicOptions
func CountTopics(opts *FindTopicOptions) (int64, error) {
- sess := db.DefaultContext().Engine().Where(opts.toConds())
+ sess := db.GetEngine(db.DefaultContext).Where(opts.toConds())
if opts.RepoID > 0 {
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
}
@@ -207,7 +207,7 @@ func CountTopics(opts *FindTopicOptions) (int64, error) {
// GetRepoTopicByName retrieves topic from name for a repo if it exist
func GetRepoTopicByName(repoID int64, topicName string) (*Topic, error) {
- return getRepoTopicByName(db.DefaultContext().Engine(), repoID, topicName)
+ return getRepoTopicByName(db.GetEngine(db.DefaultContext), repoID, topicName)
}
func getRepoTopicByName(e db.Engine, repoID int64, topicName string) (*Topic, error) {
@@ -225,7 +225,7 @@ 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.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
return nil, err
@@ -272,7 +272,7 @@ func DeleteTopic(repoID int64, topicName string) (*Topic, error) {
return nil, nil
}
- err = removeTopicFromRepo(db.DefaultContext().Engine(), repoID, topic)
+ err = removeTopicFromRepo(db.GetEngine(db.DefaultContext), repoID, topic)
return topic, err
}
@@ -286,7 +286,7 @@ func SaveTopics(repoID int64, topicNames ...string) error {
return err
}
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {