aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_reaction.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/issue_reaction.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/issue_reaction.go')
-rw-r--r--models/issue_reaction.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/models/issue_reaction.go b/models/issue_reaction.go
index 8fd22f6ca8..4e49add5c2 100644
--- a/models/issue_reaction.go
+++ b/models/issue_reaction.go
@@ -71,7 +71,7 @@ func (opts *FindReactionsOptions) toConds() builder.Cond {
// FindCommentReactions returns a ReactionList of all reactions from an comment
func FindCommentReactions(comment *Comment) (ReactionList, error) {
- return findReactions(db.DefaultContext().Engine(), FindReactionsOptions{
+ return findReactions(db.GetEngine(db.DefaultContext), FindReactionsOptions{
IssueID: comment.IssueID,
CommentID: comment.ID,
})
@@ -79,7 +79,7 @@ func FindCommentReactions(comment *Comment) (ReactionList, error) {
// FindIssueReactions returns a ReactionList of all reactions from an issue
func FindIssueReactions(issue *Issue, listOptions ListOptions) (ReactionList, error) {
- return findReactions(db.DefaultContext().Engine(), FindReactionsOptions{
+ return findReactions(db.GetEngine(db.DefaultContext), FindReactionsOptions{
ListOptions: listOptions,
IssueID: issue.ID,
CommentID: -1,
@@ -148,7 +148,7 @@ func CreateReaction(opts *ReactionOptions) (*Reaction, error) {
return nil, ErrForbiddenIssueReaction{opts.Type}
}
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
return nil, err
@@ -203,7 +203,7 @@ func deleteReaction(e db.Engine, opts *ReactionOptions) error {
// DeleteReaction deletes reaction for issue or comment.
func DeleteReaction(opts *ReactionOptions) error {
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
@@ -240,7 +240,7 @@ func (r *Reaction) LoadUser() (*User, error) {
if r.User != nil {
return r.User, nil
}
- user, err := getUserByID(db.DefaultContext().Engine(), r.UserID)
+ user, err := getUserByID(db.GetEngine(db.DefaultContext), r.UserID)
if err != nil {
return nil, err
}
@@ -314,7 +314,7 @@ func (list ReactionList) loadUsers(e db.Engine, repo *Repository) ([]*User, erro
// LoadUsers loads reactions' all users
func (list ReactionList) LoadUsers(repo *Repository) ([]*User, error) {
- return list.loadUsers(db.DefaultContext().Engine(), repo)
+ return list.loadUsers(db.GetEngine(db.DefaultContext), repo)
}
// GetFirstUsers returns first reacted user display names separated by comma