Skip to content

Commit e7128e8

Browse files
lunnylafriks
authored andcommitted
Fix sqlite lock (#5176) (#5179)
* fix sqlite lock * fix sqlite lock on getUnitType
1 parent 274ff0d commit e7128e8

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

models/notification.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor
123123

124124
for _, watch := range watches {
125125
issue.Repo.Units = nil
126-
if issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypePullRequests) {
126+
if issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypePullRequests) {
127127
continue
128128
}
129-
if !issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypeIssues) {
129+
if !issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypeIssues) {
130130
continue
131131
}
132132

models/org_team.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func (t *Team) RemoveRepository(repoID int64) error {
215215

216216
// UnitEnabled returns if the team has the given unit type enabled
217217
func (t *Team) UnitEnabled(tp UnitType) bool {
218-
if err := t.getUnits(x); err != nil {
218+
return t.unitEnabled(x, tp)
219+
}
220+
221+
func (t *Team) unitEnabled(e Engine, tp UnitType) bool {
222+
if err := t.getUnits(e); err != nil {
219223
log.Warn("Error loading repository (ID: %d) units: %s", t.ID, err.Error())
220224
}
221225

models/repo.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ func (repo *Repository) getUnits(e Engine) (err error) {
321321

322322
// CheckUnitUser check whether user could visit the unit of this repository
323323
func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool {
324-
if err := repo.getUnitsByUserID(x, userID, isAdmin); err != nil {
324+
return repo.checkUnitUser(x, userID, isAdmin, unitType)
325+
}
326+
327+
func (repo *Repository) checkUnitUser(e Engine, userID int64, isAdmin bool, unitType UnitType) bool {
328+
if err := repo.getUnitsByUserID(e, userID, isAdmin); err != nil {
325329
return false
326330
}
327331

@@ -369,7 +373,7 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
369373
var newRepoUnits = make([]*RepoUnit, 0, len(repo.Units))
370374
for _, u := range repo.Units {
371375
for _, team := range teams {
372-
if team.UnitEnabled(u.Type) {
376+
if team.unitEnabled(e, u.Type) {
373377
newRepoUnits = append(newRepoUnits, u)
374378
break
375379
}

0 commit comments

Comments
 (0)