mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 00:45:22 +02:00
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>
This commit is contained in:
parent
b22be7f594
commit
9302eba971
129 changed files with 1112 additions and 1022 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue