mirror of
https://github.com/go-gitea/gitea
synced 2025-07-30 06:08:35 +00:00
Reduce usage of db.DefaultContext
(#27073)
Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -41,7 +41,7 @@ func Branches(ctx *context.Context) {
|
||||
ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode)
|
||||
ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror
|
||||
ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) ||
|
||||
(ctx.IsSigned && repo_model.HasForkedRepo(ctx.Doer.ID, ctx.Repo.Repository.ID))
|
||||
(ctx.IsSigned && repo_model.HasForkedRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID))
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
ctx.Data["PageIsBranches"] = true
|
||||
|
||||
|
@@ -357,7 +357,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||
// "OwnForkRepo"
|
||||
var ownForkRepo *repo_model.Repository
|
||||
if ctx.Doer != nil && baseRepo.OwnerID != ctx.Doer.ID {
|
||||
repo := repo_model.GetForkedRepo(ctx.Doer.ID, baseRepo.ID)
|
||||
repo := repo_model.GetForkedRepo(ctx, ctx.Doer.ID, baseRepo.ID)
|
||||
if repo != nil {
|
||||
ownForkRepo = repo
|
||||
ctx.Data["OwnForkRepo"] = ownForkRepo
|
||||
@@ -381,13 +381,13 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||
|
||||
// 5. If the headOwner has a fork of the baseRepo - use that
|
||||
if !has {
|
||||
ci.HeadRepo = repo_model.GetForkedRepo(ci.HeadUser.ID, baseRepo.ID)
|
||||
ci.HeadRepo = repo_model.GetForkedRepo(ctx, ci.HeadUser.ID, baseRepo.ID)
|
||||
has = ci.HeadRepo != nil
|
||||
}
|
||||
|
||||
// 6. If the baseRepo is a fork and the headUser has a fork of that use that
|
||||
if !has && baseRepo.IsFork {
|
||||
ci.HeadRepo = repo_model.GetForkedRepo(ci.HeadUser.ID, baseRepo.ForkID)
|
||||
ci.HeadRepo = repo_model.GetForkedRepo(ctx, ci.HeadUser.ID, baseRepo.ForkID)
|
||||
has = ci.HeadRepo != nil
|
||||
}
|
||||
|
||||
|
@@ -130,7 +130,7 @@ func MustAllowPulls(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// User can send pull request if owns a forked repository.
|
||||
if ctx.IsSigned && repo_model.HasForkedRepo(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
if ctx.IsSigned && repo_model.HasForkedRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
ctx.Repo.PullRequest.Allowed = true
|
||||
ctx.Repo.PullRequest.HeadInfoSubURL = url.PathEscape(ctx.Doer.Name) + ":" + util.PathEscapeSegments(ctx.Repo.BranchName)
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ func SetDiffViewStyle(ctx *context.Context) {
|
||||
}
|
||||
|
||||
ctx.Data["IsSplitStyle"] = style == "split"
|
||||
if err := user_model.UpdateUserDiffViewStyle(ctx.Doer, style); err != nil {
|
||||
if err := user_model.UpdateUserDiffViewStyle(ctx, ctx.Doer, style); err != nil {
|
||||
ctx.ServerError("ErrUpdateDiffViewStyle", err)
|
||||
}
|
||||
}
|
||||
|
@@ -128,18 +128,18 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
|
||||
ctx.Data["repo_name"] = forkRepo.Name
|
||||
ctx.Data["description"] = forkRepo.Description
|
||||
ctx.Data["IsPrivate"] = forkRepo.IsPrivate || forkRepo.Owner.Visibility == structs.VisibleTypePrivate
|
||||
canForkToUser := forkRepo.OwnerID != ctx.Doer.ID && !repo_model.HasForkedRepo(ctx.Doer.ID, forkRepo.ID)
|
||||
canForkToUser := forkRepo.OwnerID != ctx.Doer.ID && !repo_model.HasForkedRepo(ctx, ctx.Doer.ID, forkRepo.ID)
|
||||
|
||||
ctx.Data["ForkRepo"] = forkRepo
|
||||
|
||||
ownedOrgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx.Doer.ID)
|
||||
ownedOrgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
|
||||
return nil
|
||||
}
|
||||
var orgs []*organization.Organization
|
||||
for _, org := range ownedOrgs {
|
||||
if forkRepo.OwnerID != org.ID && !repo_model.HasForkedRepo(org.ID, forkRepo.ID) {
|
||||
if forkRepo.OwnerID != org.ID && !repo_model.HasForkedRepo(ctx, org.ID, forkRepo.ID) {
|
||||
orgs = append(orgs, org)
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func ForkPost(ctx *context.Context) {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
|
||||
return
|
||||
}
|
||||
repo := repo_model.GetForkedRepo(ctxUser.ID, traverseParentRepo.ID)
|
||||
repo := repo_model.GetForkedRepo(ctx, ctxUser.ID, traverseParentRepo.ID)
|
||||
if repo != nil {
|
||||
ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(repo.Name))
|
||||
return
|
||||
|
@@ -80,7 +80,7 @@ func CommitInfoCache(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
|
||||
orgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx.Doer.ID)
|
||||
orgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
|
||||
return nil
|
||||
|
@@ -46,7 +46,7 @@ func SetDefaultBranchPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := repo_model.UpdateDefaultBranch(repo); err != nil {
|
||||
if err := repo_model.UpdateDefaultBranch(ctx, repo); err != nil {
|
||||
ctx.ServerError("SetDefaultBranch", err)
|
||||
return
|
||||
}
|
||||
|
@@ -1091,7 +1091,7 @@ func Forks(ctx *context.Context) {
|
||||
pager := context.NewPagination(ctx.Repo.Repository.NumForks, setting.ItemsPerPage, page, 5)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
forks, err := repo_model.GetForks(ctx.Repo.Repository, db.ListOptions{
|
||||
forks, err := repo_model.GetForks(ctx, ctx.Repo.Repository, db.ListOptions{
|
||||
Page: pager.Paginater.Current(),
|
||||
PageSize: setting.ItemsPerPage,
|
||||
})
|
||||
|
Reference in New Issue
Block a user