Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sqlite and mssql lock #5214

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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").
Expand All @@ -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()).
Expand All @@ -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()).
Expand All @@ -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)
}