aboutsummaryrefslogtreecommitdiffstats
path: root/models/pull_list.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/pull_list.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/pull_list.go')
-rw-r--r--models/pull_list.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/models/pull_list.go b/models/pull_list.go
index ed8372658d..57e2f9c85f 100644
--- a/models/pull_list.go
+++ b/models/pull_list.go
@@ -25,7 +25,7 @@ type PullRequestsOptions struct {
}
func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) {
- sess := db.DefaultContext().Engine().Where("pull_request.base_repo_id=?", baseRepoID)
+ sess := db.GetEngine(db.DefaultContext).Where("pull_request.base_repo_id=?", baseRepoID)
sess.Join("INNER", "issue", "pull_request.issue_id = issue.id")
switch opts.State {
@@ -51,7 +51,7 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xor
// by given head information (repo and branch).
func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {
prs := make([]*PullRequest, 0, 2)
- return prs, db.DefaultContext().Engine().
+ return prs, db.GetEngine(db.DefaultContext).
Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?",
repoID, branch, false, false, PullRequestFlowGithub).
Join("INNER", "issue", "issue.id = pull_request.issue_id").
@@ -62,7 +62,7 @@ func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequ
// by given base information (repo and branch).
func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequest, error) {
prs := make([]*PullRequest, 0, 2)
- return prs, db.DefaultContext().Engine().
+ return prs, db.GetEngine(db.DefaultContext).
Where("base_repo_id=? AND base_branch=? AND has_merged=? AND issue.is_closed=?",
repoID, branch, false, false).
Join("INNER", "issue", "issue.id=pull_request.issue_id").
@@ -72,7 +72,7 @@ func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequ
// GetPullRequestIDsByCheckStatus returns all pull requests according the special checking status.
func GetPullRequestIDsByCheckStatus(status PullRequestStatus) ([]int64, error) {
prs := make([]int64, 0, 10)
- return prs, db.DefaultContext().Engine().Table("pull_request").
+ return prs, db.GetEngine(db.DefaultContext).Table("pull_request").
Where("status=?", status).
Cols("pull_request.id").
Find(&prs)
@@ -144,7 +144,7 @@ func (prs PullRequestList) getIssueIDs() []int64 {
// LoadAttributes load all the prs attributes
func (prs PullRequestList) LoadAttributes() error {
- return prs.loadAttributes(db.DefaultContext().Engine())
+ return prs.loadAttributes(db.GetEngine(db.DefaultContext))
}
func (prs PullRequestList) invalidateCodeComments(e db.Engine, doer *User, repo *git.Repository, branch string) error {
@@ -169,5 +169,5 @@ func (prs PullRequestList) invalidateCodeComments(e db.Engine, doer *User, repo
// InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
func (prs PullRequestList) InvalidateCodeComments(doer *User, repo *git.Repository, branch string) error {
- return prs.invalidateCodeComments(db.DefaultContext().Engine(), doer, repo, branch)
+ return prs.invalidateCodeComments(db.GetEngine(db.DefaultContext), doer, repo, branch)
}