diff options
author | JakobDev <jakobdev@gmx.de> | 2023-10-03 12:30:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 10:30:41 +0000 |
commit | cc5df266808361c1dd3a1d17cbba712826a93d7e (patch) | |
tree | f77c59a61d3dc36f07b5b84596e4a1cde12b55cc /models/issues/issue.go | |
parent | 08507e2760638124d75774c29ef37e692a88c02d (diff) | |
download | gitea-cc5df266808361c1dd3a1d17cbba712826a93d7e.tar.gz gitea-cc5df266808361c1dd3a1d17cbba712826a93d7e.zip |
Even more `db.DefaultContext` refactor (#27352)
Part of #27065
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'models/issues/issue.go')
-rw-r--r-- | models/issues/issue.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go index 341ec8547a..6d9c8727b3 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -201,12 +201,12 @@ func (issue *Issue) IsTimetrackerEnabled(ctx context.Context) bool { } // GetPullRequest returns the issue pull request -func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) { +func (issue *Issue) GetPullRequest(ctx context.Context) (pr *PullRequest, err error) { if !issue.IsPull { return nil, fmt.Errorf("Issue is not a pull request") } - pr, err = GetPullRequestByIssueID(db.DefaultContext, issue.ID) + pr, err = GetPullRequestByIssueID(ctx, issue.ID) if err != nil { return nil, err } @@ -369,9 +369,9 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { } // GetIsRead load the `IsRead` field of the issue -func (issue *Issue) GetIsRead(userID int64) error { +func (issue *Issue) GetIsRead(ctx context.Context, userID int64) error { issueUser := &IssueUser{IssueID: issue.ID, UID: userID} - if has, err := db.GetEngine(db.DefaultContext).Get(issueUser); err != nil { + if has, err := db.GetEngine(ctx).Get(issueUser); err != nil { return err } else if !has { issue.IsRead = false @@ -382,9 +382,9 @@ func (issue *Issue) GetIsRead(userID int64) error { } // APIURL returns the absolute APIURL to this issue. -func (issue *Issue) APIURL() string { +func (issue *Issue) APIURL(ctx context.Context) string { if issue.Repo == nil { - err := issue.LoadRepo(db.DefaultContext) + err := issue.LoadRepo(ctx) if err != nil { log.Error("Issue[%d].APIURL(): %v", issue.ID, err) return "" @@ -479,9 +479,9 @@ func (issue *Issue) GetLastEventLabel() string { } // GetLastComment return last comment for the current issue. -func (issue *Issue) GetLastComment() (*Comment, error) { +func (issue *Issue) GetLastComment(ctx context.Context) (*Comment, error) { var c Comment - exist, err := db.GetEngine(db.DefaultContext).Where("type = ?", CommentTypeComment). + exist, err := db.GetEngine(ctx).Where("type = ?", CommentTypeComment). And("issue_id = ?", issue.ID).Desc("created_unix").Get(&c) if err != nil { return nil, err @@ -543,12 +543,12 @@ func GetIssueByID(ctx context.Context, id int64) (*Issue, error) { } // GetIssueWithAttrsByID returns an issue with attributes by given ID. -func GetIssueWithAttrsByID(id int64) (*Issue, error) { - issue, err := GetIssueByID(db.DefaultContext, id) +func GetIssueWithAttrsByID(ctx context.Context, id int64) (*Issue, error) { + issue, err := GetIssueByID(ctx, id) if err != nil { return nil, err } - return issue, issue.LoadAttributes(db.DefaultContext) + return issue, issue.LoadAttributes(ctx) } // GetIssuesByIDs return issues with the given IDs. @@ -600,8 +600,8 @@ func GetParticipantsIDsByIssueID(ctx context.Context, issueID int64) ([]int64, e } // IsUserParticipantsOfIssue return true if user is participants of an issue -func IsUserParticipantsOfIssue(user *user_model.User, issue *Issue) bool { - userIDs, err := issue.GetParticipantIDsByIssue(db.DefaultContext) +func IsUserParticipantsOfIssue(ctx context.Context, user *user_model.User, issue *Issue) bool { + userIDs, err := issue.GetParticipantIDsByIssue(ctx) if err != nil { log.Error(err.Error()) return false @@ -894,8 +894,8 @@ func IsErrIssueMaxPinReached(err error) bool { } // InsertIssues insert issues to database -func InsertIssues(issues ...*Issue) error { - ctx, committer, err := db.TxContext(db.DefaultContext) +func InsertIssues(ctx context.Context, issues ...*Issue) error { + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } |