summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-10-29 21:48:37 +0800
committertechknowlogick <hello@techknowlogick.com>2018-10-29 09:48:37 -0400
commit70a80e31cf6996e4fe54823fda62cb75e0bb4a13 (patch)
tree75ac21975c29a0c5ae2b10b194081b2a6cb8fc3c
parent7694c99ab343af5aaaf690232377bc439911e1a3 (diff)
downloadgitea-70a80e31cf6996e4fe54823fda62cb75e0bb4a13.tar.gz
gitea-70a80e31cf6996e4fe54823fda62cb75e0bb4a13.zip
fix sqlite and mssql lock (#5214)
-rw-r--r--models/org.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/models/org.go b/models/org.go
index c0a4172dc5..bba5e22a21 100644
--- a/models/org.go
+++ b/models/org.go
@@ -460,21 +460,21 @@ func removeOrgUser(sess *xorm.Session, orgID, userID int64) error {
return nil
}
- org, err := GetUserByID(orgID)
+ org, err := getUserByID(sess, orgID)
if err != nil {
return fmt.Errorf("GetUserByID [%d]: %v", orgID, err)
}
// Check if the user to delete is the last member in owner team.
- if isOwner, err := IsOrganizationOwner(orgID, userID); err != nil {
+ if isOwner, err := isOrganizationOwner(sess, orgID, userID); err != nil {
return err
} else if isOwner {
- t, err := org.GetOwnerTeam()
+ t, err := org.getOwnerTeam(sess)
if err != nil {
return err
}
if t.NumMembers == 1 {
- if err := t.GetMembers(); err != nil {
+ if err := t.getMembers(sess); err != nil {
return err
}
if t.Members[0].ID == userID {
@@ -490,7 +490,7 @@ func removeOrgUser(sess *xorm.Session, orgID, userID int64) error {
}
// Delete all repository accesses and unwatch them.
- env, err := org.AccessibleReposEnv(userID)
+ env, err := org.accessibleReposEnv(sess, userID)
if err != nil {
return fmt.Errorf("AccessibleReposEnv: %v", err)
}
@@ -618,16 +618,26 @@ type accessibleReposEnv struct {
org *User
userID int64
teamIDs []int64
+ e Engine
}
// AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org`
// that are accessible to the specified user.
func (org *User) AccessibleReposEnv(userID int64) (AccessibleReposEnvironment, error) {
- teamIDs, err := org.GetUserTeamIDs(userID)
+ return org.accessibleReposEnv(x, userID)
+}
+
+func (org *User) accessibleReposEnv(e Engine, userID int64) (AccessibleReposEnvironment, error) {
+ teamIDs, err := org.getUserTeamIDs(e, userID)
if err != nil {
return nil, err
}
- return &accessibleReposEnv{org: org, userID: userID, teamIDs: teamIDs}, nil
+ return &accessibleReposEnv{
+ org: org,
+ userID: userID,
+ teamIDs: teamIDs,
+ e: e,
+ }, nil
}
func (env *accessibleReposEnv) cond() builder.Cond {
@@ -642,7 +652,7 @@ func (env *accessibleReposEnv) cond() builder.Cond {
}
func (env *accessibleReposEnv) CountRepos() (int64, error) {
- repoCount, err := x.
+ repoCount, err := env.e.
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id").
Where(env.cond()).
Distinct("`repository`.id").
@@ -659,7 +669,7 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) {
}
repoIDs := make([]int64, 0, pageSize)
- return repoIDs, x.
+ return repoIDs, env.e.
Table("repository").
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id").
Where(env.cond()).
@@ -681,14 +691,14 @@ func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*Repository, error)
return repos, nil
}
- return repos, x.
+ return repos, env.e.
In("`repository`.id", repoIDs).
Find(&repos)
}
func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) {
repoIDs := make([]int64, 0, 10)
- return repoIDs, x.
+ return repoIDs, env.e.
Table("repository").
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true).
Where(env.cond()).
@@ -709,7 +719,7 @@ func (env *accessibleReposEnv) MirrorRepos() ([]*Repository, error) {
return repos, nil
}
- return repos, x.
+ return repos, env.e.
In("`repository`.id", repoIDs).
Find(&repos)
}