aboutsummaryrefslogtreecommitdiffstats
path: root/services/convert
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-07-22 22:14:27 +0800
committerGitHub <noreply@github.com>2023-07-22 22:14:27 +0800
commitb167f35113e643ccdb17a2dde55bdec5960b284b (patch)
tree99a6e53bf1a9d4c9199c19113650cc48a8c1fd0e /services/convert
parentc42b71877edb4830b9573101d20853222d66fb3c (diff)
downloadgitea-b167f35113e643ccdb17a2dde55bdec5960b284b.tar.gz
gitea-b167f35113e643ccdb17a2dde55bdec5960b284b.zip
Add context parameter to some database functions (#26055)
To avoid deadlock problem, almost database related functions should be have ctx as the first parameter. This PR do a refactor for some of these functions.
Diffstat (limited to 'services/convert')
-rw-r--r--services/convert/convert.go12
-rw-r--r--services/convert/issue_comment.go2
2 files changed, 7 insertions, 7 deletions
diff --git a/services/convert/convert.go b/services/convert/convert.go
index 25c89747e3..cb246a8b4b 100644
--- a/services/convert/convert.go
+++ b/services/convert/convert.go
@@ -56,16 +56,16 @@ func ToBranch(ctx context.Context, repo *repo_model.Repository, branchName strin
var canPush bool
var err error
if user != nil {
- hasPerm, err = access_model.HasAccessUnit(db.DefaultContext, user, repo, unit.TypeCode, perm.AccessModeWrite)
+ hasPerm, err = access_model.HasAccessUnit(ctx, user, repo, unit.TypeCode, perm.AccessModeWrite)
if err != nil {
return nil, err
}
- perms, err := access_model.GetUserRepoPermission(db.DefaultContext, repo, user)
+ perms, err := access_model.GetUserRepoPermission(ctx, repo, user)
if err != nil {
return nil, err
}
- canPush = issues_model.CanMaintainerWriteToBranch(perms, branchName, user)
+ canPush = issues_model.CanMaintainerWriteToBranch(ctx, perms, branchName, user)
}
return &api.Branch{
@@ -94,13 +94,13 @@ func ToBranch(ctx context.Context, repo *repo_model.Repository, branchName strin
}
if user != nil {
- permission, err := access_model.GetUserRepoPermission(db.DefaultContext, repo, user)
+ permission, err := access_model.GetUserRepoPermission(ctx, repo, user)
if err != nil {
return nil, err
}
bp.Repo = repo
- branch.UserCanPush = bp.CanUserPush(db.DefaultContext, user)
- branch.UserCanMerge = git_model.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission)
+ branch.UserCanPush = bp.CanUserPush(ctx, user)
+ branch.UserCanMerge = git_model.IsUserMergeWhitelisted(ctx, bp, user.ID, permission)
}
return branch, nil
diff --git a/services/convert/issue_comment.go b/services/convert/issue_comment.go
index b0145c38e6..1308051e7c 100644
--- a/services/convert/issue_comment.go
+++ b/services/convert/issue_comment.go
@@ -114,7 +114,7 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
}
if c.Time != nil {
- err = c.Time.LoadAttributes()
+ err = c.Time.LoadAttributes(ctx)
if err != nil {
log.Error("Time.LoadAttributes: %v", err)
return nil