summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-04-28 13:48:48 +0200
committerGitHub <noreply@github.com>2022-04-28 13:48:48 +0200
commit06e4687cecaed41500b653e5b8685f48b8b18310 (patch)
treea98dd6d0139ba5d89c7e08d3c52930d66a77119b /modules
parent332b2ecd214a79b49f3798f4f27fe02b23a17bf8 (diff)
downloadgitea-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')
-rw-r--r--modules/context/repo.go4
-rw-r--r--modules/convert/convert.go3
-rw-r--r--modules/convert/issue.go2
-rw-r--r--modules/convert/pull.go8
-rw-r--r--modules/notification/mail/mail.go2
-rw-r--r--modules/test/context_tests.go2
6 files changed, 11 insertions, 10 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 4687434455..a02bb7e869 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -285,7 +285,7 @@ func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) {
return
}
- perm, err := models.GetUserRepoPermission(templateRepo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, templateRepo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
@@ -351,7 +351,7 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
return
}
- ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.Doer)
+ ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
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
diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go
index 6636d18b99..138e438751 100644
--- a/modules/notification/mail/mail.go
+++ b/modules/notification/mail/mail.go
@@ -169,7 +169,7 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *m
log.Error("comment.Issue.LoadPullRequest: %v", err)
return
}
- if err = comment.Issue.PullRequest.LoadBaseRepo(); err != nil {
+ if err = comment.Issue.PullRequest.LoadBaseRepoCtx(ctx); err != nil {
log.Error("comment.Issue.PullRequest.LoadBaseRepo: %v", err)
return
}
diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go
index 2c6ae2f853..a05b221af8 100644
--- a/modules/test/context_tests.go
+++ b/modules/test/context_tests.go
@@ -60,7 +60,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID)
assert.NoError(t, err)
ctx.Repo.RepoLink = ctx.Repo.Repository.Link()
- ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx.Repo.Repository, ctx.Doer)
+ ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx, ctx.Repo.Repository, ctx.Doer)
assert.NoError(t, err)
}