Skip to content

Commit 2b7c366

Browse files
authored
fix sqlite lock (#5184)
* fix sqlite lock * fix bug Co-Authored-By: lunny <[email protected]> * fix bug Co-Authored-By: lunny <[email protected]>
1 parent 99c09df commit 2b7c366

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

models/issue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository,
655655
}
656656

657657
// Check for open dependencies
658-
if isClosed && issue.Repo.IsDependenciesEnabled() {
658+
if isClosed && issue.Repo.isDependenciesEnabled(e) {
659659
// only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
660-
noDeps, err := IssueNoDependenciesLeft(issue)
660+
noDeps, err := issueNoDependenciesLeft(e, issue)
661661
if err != nil {
662662
return err
663663
}
@@ -721,6 +721,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
721721
if err = sess.Commit(); err != nil {
722722
return fmt.Errorf("Commit: %v", err)
723723
}
724+
sess.Close()
724725

725726
mode, _ := AccessLevel(issue.Poster.ID, issue.Repo)
726727
if issue.IsPull {

models/issue_dependency.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ func issueDepExists(e Engine, issueID int64, depID int64) (bool, error) {
113113

114114
// IssueNoDependenciesLeft checks if issue can be closed
115115
func IssueNoDependenciesLeft(issue *Issue) (bool, error) {
116+
return issueNoDependenciesLeft(x, issue)
117+
}
116118

117-
exists, err := x.
119+
func issueNoDependenciesLeft(e Engine, issue *Issue) (bool, error) {
120+
exists, err := e.
118121
Table("issue_dependency").
119122
Select("issue.*").
120123
Join("INNER", "issue", "issue.id = issue_dependency.dependency_id").
@@ -127,9 +130,13 @@ func IssueNoDependenciesLeft(issue *Issue) (bool, error) {
127130

128131
// IsDependenciesEnabled returns if dependecies are enabled and returns the default setting if not set.
129132
func (repo *Repository) IsDependenciesEnabled() bool {
133+
return repo.isDependenciesEnabled(x)
134+
}
135+
136+
func (repo *Repository) isDependenciesEnabled(e Engine) bool {
130137
var u *RepoUnit
131138
var err error
132-
if u, err = repo.GetUnit(UnitTypeIssues); err != nil {
139+
if u, err = repo.getUnit(e, UnitTypeIssues); err != nil {
133140
log.Trace("%s", err)
134141
return setting.Service.DefaultEnableDependencies
135142
}

models/repo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ func (repo *Repository) MustGetUnit(tp UnitType) *RepoUnit {
448448

449449
// GetUnit returns a RepoUnit object
450450
func (repo *Repository) GetUnit(tp UnitType) (*RepoUnit, error) {
451-
if err := repo.getUnits(x); err != nil {
451+
return repo.getUnit(x, tp)
452+
}
453+
454+
func (repo *Repository) getUnit(e Engine, tp UnitType) (*RepoUnit, error) {
455+
if err := repo.getUnits(e); err != nil {
452456
return nil, err
453457
}
454458
for _, unit := range repo.Units {

0 commit comments

Comments
 (0)