diff options
author | 6543 <6543@obermui.de> | 2022-04-28 13:48:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 13:48:48 +0200 |
commit | 06e4687cecaed41500b653e5b8685f48b8b18310 (patch) | |
tree | a98dd6d0139ba5d89c7e08d3c52930d66a77119b /modules/convert | |
parent | 332b2ecd214a79b49f3798f4f27fe02b23a17bf8 (diff) | |
download | gitea-06e4687cecaed41500b653e5b8685f48b8b18310.tar.gz gitea-06e4687cecaed41500b653e5b8685f48b8b18310.zip |
more context for models (#19511)
make more usage of context, to have more db transaction in one session
(make diff of #9307 smaller)
Diffstat (limited to 'modules/convert')
-rw-r--r-- | modules/convert/convert.go | 3 | ||||
-rw-r--r-- | modules/convert/issue.go | 2 | ||||
-rw-r--r-- | modules/convert/pull.go | 8 |
3 files changed, 7 insertions, 6 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 43300f603e..3f565f76e0 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" repo_model "code.gitea.io/gitea/models/repo" @@ -74,7 +75,7 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *mod } if user != nil { - permission, err := models.GetUserRepoPermission(repo, user) + permission, err := models.GetUserRepoPermission(db.DefaultContext, repo, user) if err != nil { return nil, err } diff --git a/modules/convert/issue.go b/modules/convert/issue.go index 6cdb10f7da..bf116e2283 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -24,7 +24,7 @@ import ( // Required - Poster, Labels, // Optional - Milestone, Assignee, PullRequest func ToAPIIssue(issue *models.Issue) *api.Issue { - if err := issue.LoadLabels(); err != nil { + if err := issue.LoadLabels(db.DefaultContext); err != nil { return &api.Issue{} } if err := issue.LoadPoster(); err != nil { diff --git a/modules/convert/pull.go b/modules/convert/pull.go index 3b39e3d2c1..6034327a9d 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -33,17 +33,17 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo } apiIssue := ToAPIIssue(pr.Issue) - if err := pr.LoadBaseRepo(); err != nil { + if err := pr.LoadBaseRepoCtx(ctx); err != nil { log.Error("GetRepositoryById[%d]: %v", pr.ID, err) return nil } - if err := pr.LoadHeadRepo(); err != nil { + if err := pr.LoadHeadRepoCtx(ctx); err != nil { log.Error("GetRepositoryById[%d]: %v", pr.ID, err) return nil } - p, err := models.GetUserRepoPermission(pr.BaseRepo, doer) + p, err := models.GetUserRepoPermission(ctx, pr.BaseRepo, doer) if err != nil { log.Error("GetUserRepoPermission[%d]: %v", pr.BaseRepoID, err) p.AccessMode = perm.AccessModeNone @@ -130,7 +130,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo } if pr.HeadRepo != nil && pr.Flow == models.PullRequestFlowGithub { - p, err := models.GetUserRepoPermission(pr.HeadRepo, doer) + p, err := models.GetUserRepoPermission(ctx, pr.HeadRepo, doer) if err != nil { log.Error("GetUserRepoPermission[%d]: %v", pr.HeadRepoID, err) p.AccessMode = perm.AccessModeNone |