1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Small opitimization for getUserTeams (#954)

* Small opitimization for getUserTeams

* more compact
This commit is contained in:
Lunny Xiao 2017-02-16 12:06:23 +08:00 committed by GitHub
parent 134f3e6e09
commit 0642cb330c

View file

@ -438,27 +438,12 @@ func GetTeamMembers(teamID int64) ([]*User, error) {
return getTeamMembers(x, teamID) return getTeamMembers(x, teamID)
} }
func getUserTeams(e Engine, orgID, userID int64) ([]*Team, error) { func getUserTeams(e Engine, orgID, userID int64) (teams []*Team, err error) {
tus := make([]*TeamUser, 0, 5) return teams, e.
if err := e. Join("INNER", "team_user", "team_user.team_id = team.id").
Where("uid=?", userID). Where("team.org_id = ?", orgID).
And("org_id=?", orgID). And("team_user.uid=?", userID).
Find(&tus); err != nil { Find(&teams)
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
} }
// GetUserTeams returns all teams that user belongs to in given organization. // GetUserTeams returns all teams that user belongs to in given organization.