mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Prevent deadlock in create issue (#17970)
This commit is contained in:
		@@ -141,7 +141,7 @@ func (issue *Issue) isTimetrackerEnabled(ctx context.Context) bool {
 | 
				
			|||||||
		log.Error(fmt.Sprintf("loadRepo: %v", err))
 | 
							log.Error(fmt.Sprintf("loadRepo: %v", err))
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return issue.Repo.IsTimetrackerEnabled()
 | 
						return issue.Repo.IsTimetrackerEnabledCtx(ctx)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GetPullRequest returns the issue pull request
 | 
					// GetPullRequest returns the issue pull request
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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.
 | 
					// 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 {
 | 
					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 {
 | 
						if !setting.Service.EnableTimetracking {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var u *RepoUnit
 | 
						var u *RepoUnit
 | 
				
			||||||
	var err error
 | 
						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 setting.Service.DefaultEnableTimetracking
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return u.IssuesConfig().EnableTimetracker
 | 
						return u.IssuesConfig().EnableTimetracker
 | 
				
			||||||
@@ -59,7 +64,7 @@ func (repo *Repository) IsDependenciesEnabled() bool {
 | 
				
			|||||||
func (repo *Repository) IsDependenciesEnabledCtx(ctx context.Context) bool {
 | 
					func (repo *Repository) IsDependenciesEnabledCtx(ctx context.Context) bool {
 | 
				
			||||||
	var u *RepoUnit
 | 
						var u *RepoUnit
 | 
				
			||||||
	var err error
 | 
						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)
 | 
							log.Trace("%s", err)
 | 
				
			||||||
		return setting.Service.DefaultEnableDependencies
 | 
							return setting.Service.DefaultEnableDependencies
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -312,10 +312,11 @@ func (repo *Repository) MustGetUnit(tp unit.Type) *RepoUnit {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// GetUnit returns a RepoUnit object
 | 
					// GetUnit returns a RepoUnit object
 | 
				
			||||||
func (repo *Repository) GetUnit(tp unit.Type) (*RepoUnit, error) {
 | 
					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 {
 | 
						if err := repo.LoadUnits(ctx); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user