summaryrefslogtreecommitdiffstats
path: root/models/repo
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-12-13 22:59:39 +0000
committerGitHub <noreply@github.com>2021-12-13 17:59:39 -0500
commiteba07867ef180cf094ce81be93d673d32a6df712 (patch)
tree12b33fa86bbfab64100bde029e59d9d56fca420d /models/repo
parent39eb82446c6fe5da3d79124e1f701f3795625b69 (diff)
downloadgitea-eba07867ef180cf094ce81be93d673d32a6df712.tar.gz
gitea-eba07867ef180cf094ce81be93d673d32a6df712.zip
Prevent deadlock in create issue (#17970)
Diffstat (limited to 'models/repo')
-rw-r--r--models/repo/issue.go9
-rw-r--r--models/repo/repo.go5
2 files changed, 10 insertions, 4 deletions
diff --git a/models/repo/issue.go b/models/repo/issue.go
index 3edcc7b5a0..9f0fa3bad9 100644
--- a/models/repo/issue.go
+++ b/models/repo/issue.go
@@ -28,13 +28,18 @@ func (repo *Repository) CanEnableTimetracker() bool {
// IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
func (repo *Repository) IsTimetrackerEnabled() bool {
+ return repo.IsTimetrackerEnabledCtx(db.DefaultContext)
+}
+
+// IsTimetrackerEnabledCtx returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
+func (repo *Repository) IsTimetrackerEnabledCtx(ctx context.Context) bool {
if !setting.Service.EnableTimetracking {
return false
}
var u *RepoUnit
var err error
- if u, err = repo.GetUnit(unit.TypeIssues); err != nil {
+ if u, err = repo.GetUnitCtx(ctx, unit.TypeIssues); err != nil {
return setting.Service.DefaultEnableTimetracking
}
return u.IssuesConfig().EnableTimetracker
@@ -59,7 +64,7 @@ func (repo *Repository) IsDependenciesEnabled() bool {
func (repo *Repository) IsDependenciesEnabledCtx(ctx context.Context) bool {
var u *RepoUnit
var err error
- if u, err = repo.getUnit(ctx, unit.TypeIssues); err != nil {
+ if u, err = repo.GetUnitCtx(ctx, unit.TypeIssues); err != nil {
log.Trace("%s", err)
return setting.Service.DefaultEnableDependencies
}
diff --git a/models/repo/repo.go b/models/repo/repo.go
index 8907691dde..e5943b5a2d 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -312,10 +312,11 @@ func (repo *Repository) MustGetUnit(tp unit.Type) *RepoUnit {
// GetUnit returns a RepoUnit object
func (repo *Repository) GetUnit(tp unit.Type) (*RepoUnit, error) {
- return repo.getUnit(db.DefaultContext, tp)
+ return repo.GetUnitCtx(db.DefaultContext, tp)
}
-func (repo *Repository) getUnit(ctx context.Context, tp unit.Type) (*RepoUnit, error) {
+// GetUnitCtx returns a RepoUnit object
+func (repo *Repository) GetUnitCtx(ctx context.Context, tp unit.Type) (*RepoUnit, error) {
if err := repo.LoadUnits(ctx); err != nil {
return nil, err
}