diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-16 12:06:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 12:06:23 +0800 |
commit | 0642cb330cbdb58632d6b7b5831200ff339bba8a (patch) | |
tree | ea6713ad6a9743edf663240c02e3cccafd204a1a /models/org_team.go | |
parent | 134f3e6e09ed0583bc377a08ef46a51013635a2e (diff) | |
download | gitea-0642cb330cbdb58632d6b7b5831200ff339bba8a.tar.gz gitea-0642cb330cbdb58632d6b7b5831200ff339bba8a.zip |
Small opitimization for getUserTeams (#954)
* Small opitimization for getUserTeams
* more compact
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/models/org_team.go b/models/org_team.go index d9ad0ba28f..b795c90e07 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -438,27 +438,12 @@ func GetTeamMembers(teamID int64) ([]*User, error) { return getTeamMembers(x, teamID) } -func getUserTeams(e Engine, orgID, userID int64) ([]*Team, error) { - tus := make([]*TeamUser, 0, 5) - if err := e. - Where("uid=?", userID). - And("org_id=?", orgID). - Find(&tus); err != nil { - return nil, err - } - - ts := make([]*Team, len(tus)) - for i, tu := range tus { - t := new(Team) - has, err := e.Id(tu.TeamID).Get(t) - if err != nil { - return nil, err - } else if !has { - return nil, ErrTeamNotExist - } - ts[i] = t - } - return ts, nil +func getUserTeams(e Engine, orgID, userID int64) (teams []*Team, err error) { + return teams, e. + Join("INNER", "team_user", "team_user.team_id = team.id"). + Where("team.org_id = ?", orgID). + And("team_user.uid=?", userID). + Find(&teams) } // GetUserTeams returns all teams that user belongs to in given organization. |