diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-16 12:07:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 12:07:58 +0800 |
commit | 7fd14bf7bd96849f3f64a3bcbfb914050c063660 (patch) | |
tree | 821348d5bb80838efb4afbf057e3672ec0736d53 /models/org_team.go | |
parent | 46320f9630087e010a31ab580294cc9137eb865f (diff) | |
download | gitea-7fd14bf7bd96849f3f64a3bcbfb914050c063660.tar.gz gitea-7fd14bf7bd96849f3f64a3bcbfb914050c063660.zip |
optimization for team get repos (#953)
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/models/org_team.go b/models/org_team.go index b795c90e07..dfdffa70b2 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -37,22 +37,8 @@ func (t *Team) IsMember(userID int64) bool { } func (t *Team) getRepositories(e Engine) (err error) { - teamRepos := make([]*TeamRepo, 0, t.NumRepos) - if err = x. - Where("team_id=?", t.ID). - Find(&teamRepos); err != nil { - return fmt.Errorf("get team-repos: %v", err) - } - - t.Repos = make([]*Repository, 0, len(teamRepos)) - for i := range teamRepos { - repo, err := getRepositoryByID(e, teamRepos[i].RepoID) - if err != nil { - return fmt.Errorf("getRepositoryById(%d): %v", teamRepos[i].RepoID, err) - } - t.Repos = append(t.Repos, repo) - } - return nil + return e.Join("INNER", "team_repo", "repository.id = team_repo.repo_id"). + Where("team_repo.team_id=?", t.ID).Find(&t.Repos) } // GetRepositories returns all repositories in team of organization. |