diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-10-25 22:30:25 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-10-25 17:30:25 +0300 |
commit | e7128e8c416924f467620a5e10943eed2888c11e (patch) | |
tree | 80aa34858615b635d82dfbc274c7cb555d00553b | |
parent | 274ff0d011775c67dc3666986b8d7ca57182fbcc (diff) | |
download | gitea-e7128e8c416924f467620a5e10943eed2888c11e.tar.gz gitea-e7128e8c416924f467620a5e10943eed2888c11e.zip |
Fix sqlite lock (#5176) (#5179)
* fix sqlite lock
* fix sqlite lock on getUnitType
-rw-r--r-- | models/notification.go | 4 | ||||
-rw-r--r-- | models/org_team.go | 6 | ||||
-rw-r--r-- | models/repo.go | 8 |
3 files changed, 13 insertions, 5 deletions
diff --git a/models/notification.go b/models/notification.go index 8c36c0c5c9..cda2916fae 100644 --- a/models/notification.go +++ b/models/notification.go @@ -123,10 +123,10 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor for _, watch := range watches { issue.Repo.Units = nil - if issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypePullRequests) { + if issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypePullRequests) { continue } - if !issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypeIssues) { + if !issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypeIssues) { continue } diff --git a/models/org_team.go b/models/org_team.go index 3b37f936ff..505f11d39d 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -215,7 +215,11 @@ func (t *Team) RemoveRepository(repoID int64) error { // UnitEnabled returns if the team has the given unit type enabled func (t *Team) UnitEnabled(tp UnitType) bool { - if err := t.getUnits(x); err != nil { + return t.unitEnabled(x, tp) +} + +func (t *Team) unitEnabled(e Engine, tp UnitType) bool { + if err := t.getUnits(e); err != nil { log.Warn("Error loading repository (ID: %d) units: %s", t.ID, err.Error()) } diff --git a/models/repo.go b/models/repo.go index c334431be7..25def6ad8f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -321,7 +321,11 @@ func (repo *Repository) getUnits(e Engine) (err error) { // CheckUnitUser check whether user could visit the unit of this repository func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool { - if err := repo.getUnitsByUserID(x, userID, isAdmin); err != nil { + return repo.checkUnitUser(x, userID, isAdmin, unitType) +} + +func (repo *Repository) checkUnitUser(e Engine, userID int64, isAdmin bool, unitType UnitType) bool { + if err := repo.getUnitsByUserID(e, userID, isAdmin); err != nil { return false } @@ -369,7 +373,7 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) ( var newRepoUnits = make([]*RepoUnit, 0, len(repo.Units)) for _, u := range repo.Units { for _, team := range teams { - if team.UnitEnabled(u.Type) { + if team.unitEnabled(e, u.Type) { newRepoUnits = append(newRepoUnits, u) break } |