mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
more context for models (#19511)
make more usage of context, to have more db transaction in one session (make diff of #9307 smaller)
This commit is contained in:
parent
332b2ecd21
commit
06e4687cec
54 changed files with 275 additions and 245 deletions
|
@ -7,6 +7,7 @@ package repo
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
stdCtx "context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -1052,8 +1053,8 @@ func NewIssuePost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
|
||||
func roleDescriptor(repo *repo_model.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
|
||||
perm, err := models.GetUserRepoPermission(repo, poster)
|
||||
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
|
||||
perm, err := models.GetUserRepoPermission(ctx, repo, poster)
|
||||
if err != nil {
|
||||
return models.RoleDescriptorNone, err
|
||||
}
|
||||
|
@ -1350,7 +1351,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
// check if dependencies can be created across repositories
|
||||
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
|
||||
|
||||
if issue.ShowRole, err = roleDescriptor(repo, issue.Poster, issue); err != nil {
|
||||
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue); err != nil {
|
||||
ctx.ServerError("roleDescriptor", err)
|
||||
return
|
||||
}
|
||||
|
@ -1389,7 +1390,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
continue
|
||||
}
|
||||
|
||||
comment.ShowRole, err = roleDescriptor(repo, comment.Poster, issue)
|
||||
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue)
|
||||
if err != nil {
|
||||
ctx.ServerError("roleDescriptor", err)
|
||||
return
|
||||
|
@ -1488,7 +1489,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
continue
|
||||
}
|
||||
|
||||
c.ShowRole, err = roleDescriptor(repo, c.Poster, issue)
|
||||
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue)
|
||||
if err != nil {
|
||||
ctx.ServerError("roleDescriptor", err)
|
||||
return
|
||||
|
@ -1526,10 +1527,10 @@ func ViewIssue(ctx *context.Context) {
|
|||
ctx.Data["AllowMerge"] = false
|
||||
|
||||
if ctx.IsSigned {
|
||||
if err := pull.LoadHeadRepo(); err != nil {
|
||||
if err := pull.LoadHeadRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
} else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch {
|
||||
perm, err := models.GetUserRepoPermission(pull.HeadRepo, ctx.Doer)
|
||||
perm, err := models.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
|
@ -1545,10 +1546,10 @@ func ViewIssue(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := pull.LoadBaseRepo(); err != nil {
|
||||
if err := pull.LoadBaseRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
}
|
||||
perm, err := models.GetUserRepoPermission(pull.BaseRepo, ctx.Doer)
|
||||
perm, err := models.GetUserRepoPermission(ctx, pull.BaseRepo, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
|
@ -2038,7 +2039,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = issue_service.IsValidTeamReviewRequest(team, ctx.Doer, action == "attach", issue)
|
||||
err = issue_service.IsValidTeamReviewRequest(ctx, team, ctx.Doer, action == "attach", issue)
|
||||
if err != nil {
|
||||
if models.IsErrNotValidReviewRequest(err) {
|
||||
log.Warn(
|
||||
|
@ -2076,7 +2077,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = issue_service.IsValidReviewRequest(reviewer, ctx.Doer, action == "attach", issue, nil)
|
||||
err = issue_service.IsValidReviewRequest(ctx, reviewer, ctx.Doer, action == "attach", issue, nil)
|
||||
if err != nil {
|
||||
if models.IsErrNotValidReviewRequest(err) {
|
||||
log.Warn(
|
||||
|
@ -2919,7 +2920,7 @@ func filterXRefComments(ctx *context.Context, issue *models.Issue) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
perm, err := models.GetUserRepoPermission(c.RefRepo, ctx.Doer)
|
||||
perm, err := models.GetUserRepoPermission(ctx, c.RefRepo, ctx.Doer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue