diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-14 11:46:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-14 11:46:46 +0800 |
commit | 55ae78208e38eb92d916c0b3c45c4e9cebfc14c9 (patch) | |
tree | 701df21e8acd86ab623dca1a5e3f0f490db3af19 /models | |
parent | 1ec6b1a2589509ac855ec12b4f79e70ef0ee4f66 (diff) | |
download | gitea-55ae78208e38eb92d916c0b3c45c4e9cebfc14c9.tar.gz gitea-55ae78208e38eb92d916c0b3c45c4e9cebfc14c9.zip |
Small optimization for getTeamIDs (#919)
* small optimization for getTeamIDs
* rename getOrgTeamIDs to getUserTeamIDs and remove orderby
Diffstat (limited to 'models')
-rw-r--r-- | models/models.go | 1 | ||||
-rw-r--r-- | models/org.go | 22 |
2 files changed, 13 insertions, 10 deletions
diff --git a/models/models.go b/models/models.go index 7f0ef59547..27b49755aa 100644 --- a/models/models.go +++ b/models/models.go @@ -30,6 +30,7 @@ import ( // Engine represents a xorm engine or session. type Engine interface { + Table(tableNameOrBean interface{}) *xorm.Session Count(interface{}) (int64, error) Decr(column string, arg ...interface{}) *xorm.Session Delete(interface{}) (int64, error) diff --git a/models/org.go b/models/org.go index f68c2b9fcb..6da54300cb 100644 --- a/models/org.go +++ b/models/org.go @@ -563,18 +563,20 @@ func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team, Find(&teams) } +func (org *User) getUserTeamIDs(e Engine, userID int64) ([]int64, error) { + teamIDs := make([]int64, 0, org.NumTeams) + return teamIDs, e. + Table("team"). + Cols("team.id"). + Where("`team_user`.org_id = ?", org.ID). + Join("INNER", "team_user", "`team_user`.team_id = team.id"). + And("`team_user`.uid = ?", userID). + Find(&teamIDs) +} + // GetUserTeamIDs returns of all team IDs of the organization that user is member of. func (org *User) GetUserTeamIDs(userID int64) ([]int64, error) { - teams, err := org.getUserTeams(x, userID, "team.id") - if err != nil { - return nil, fmt.Errorf("getUserTeams [%d]: %v", userID, err) - } - - teamIDs := make([]int64, len(teams)) - for i := range teams { - teamIDs[i] = teams[i].ID - } - return teamIDs, nil + return org.getUserTeamIDs(x, userID) } // GetUserTeams returns all teams that belong to user, |