mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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>
This commit is contained in:
		@@ -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
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user