diff options
author | zeripath <art27@cantab.net> | 2021-09-23 16:45:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-23 23:45:36 +0800 |
commit | 9302eba971611601c3ebf6024e22a11c63f4e151 (patch) | |
tree | a3e5583986161ef62e7affc694098279ecf2217d /models/project_board.go | |
parent | b22be7f594401d7bd81196750456ce52185bd391 (diff) | |
download | gitea-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/project_board.go')
-rw-r--r-- | models/project_board.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/models/project_board.go b/models/project_board.go index 901850e511..6a35868511 100644 --- a/models/project_board.go +++ b/models/project_board.go @@ -100,13 +100,13 @@ func createBoardsForProjectsType(sess *xorm.Session, project *Project) error { // NewProjectBoard adds a new project board to a given project func NewProjectBoard(board *ProjectBoard) error { - _, err := db.DefaultContext().Engine().Insert(board) + _, err := db.GetEngine(db.DefaultContext).Insert(board) return err } // DeleteProjectBoardByID removes all issues references to the project board. func DeleteProjectBoardByID(boardID int64) error { - sess := db.DefaultContext().NewSession() + sess := db.NewSession(db.DefaultContext) defer sess.Close() if err := sess.Begin(); err != nil { return err @@ -146,7 +146,7 @@ func deleteProjectBoardByProjectID(e db.Engine, projectID int64) error { // GetProjectBoard fetches the current board of a project func GetProjectBoard(boardID int64) (*ProjectBoard, error) { - return getProjectBoard(db.DefaultContext().Engine(), boardID) + return getProjectBoard(db.GetEngine(db.DefaultContext), boardID) } func getProjectBoard(e db.Engine, boardID int64) (*ProjectBoard, error) { @@ -164,7 +164,7 @@ func getProjectBoard(e db.Engine, boardID int64) (*ProjectBoard, error) { // UpdateProjectBoard updates a project board func UpdateProjectBoard(board *ProjectBoard) error { - return updateProjectBoard(db.DefaultContext().Engine(), board) + return updateProjectBoard(db.GetEngine(db.DefaultContext), board) } func updateProjectBoard(e db.Engine, board *ProjectBoard) error { @@ -186,7 +186,7 @@ func updateProjectBoard(e db.Engine, board *ProjectBoard) error { // GetProjectBoards fetches all boards related to a project // if no default board set, first board is a temporary "Uncategorized" board func GetProjectBoards(projectID int64) (ProjectBoardList, error) { - return getProjectBoards(db.DefaultContext().Engine(), projectID) + return getProjectBoards(db.GetEngine(db.DefaultContext), projectID) } func getProjectBoards(e db.Engine, projectID int64) ([]*ProjectBoard, error) { @@ -226,7 +226,7 @@ func getDefaultBoard(e db.Engine, projectID int64) (*ProjectBoard, error) { // SetDefaultBoard represents a board for issues not assigned to one // if boardID is 0 unset default func SetDefaultBoard(projectID, boardID int64) error { - _, err := db.DefaultContext().Engine().Where(builder.Eq{ + _, err := db.GetEngine(db.DefaultContext).Where(builder.Eq{ "project_id": projectID, "`default`": true, }).Cols("`default`").Update(&ProjectBoard{Default: false}) @@ -235,7 +235,7 @@ func SetDefaultBoard(projectID, boardID int64) error { } if boardID > 0 { - _, err = db.DefaultContext().Engine().ID(boardID).Where(builder.Eq{"project_id": projectID}). + _, err = db.GetEngine(db.DefaultContext).ID(boardID).Where(builder.Eq{"project_id": projectID}). Cols("`default`").Update(&ProjectBoard{Default: true}) } @@ -293,7 +293,7 @@ func (bs ProjectBoardList) LoadIssues() (IssueList, error) { // UpdateProjectBoardSorting update project board sorting func UpdateProjectBoardSorting(bs ProjectBoardList) error { for i := range bs { - _, err := db.DefaultContext().Engine().ID(bs[i].ID).Cols( + _, err := db.GetEngine(db.DefaultContext).ID(bs[i].ID).Cols( "sorting", ).Update(bs[i]) if err != nil { |