Small optimization for getTeamIDs (#919)
* small optimization for getTeamIDs * rename getOrgTeamIDs to getUserTeamIDs and remove orderby
This commit is contained in:
parent
1ec6b1a258
commit
55ae78208e
2 changed files with 13 additions and 10 deletions
|
@ -30,6 +30,7 @@ import (
|
||||||
|
|
||||||
// Engine represents a xorm engine or session.
|
// Engine represents a xorm engine or session.
|
||||||
type Engine interface {
|
type Engine interface {
|
||||||
|
Table(tableNameOrBean interface{}) *xorm.Session
|
||||||
Count(interface{}) (int64, error)
|
Count(interface{}) (int64, error)
|
||||||
Decr(column string, arg ...interface{}) *xorm.Session
|
Decr(column string, arg ...interface{}) *xorm.Session
|
||||||
Delete(interface{}) (int64, error)
|
Delete(interface{}) (int64, error)
|
||||||
|
|
|
@ -563,18 +563,20 @@ func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team,
|
||||||
Find(&teams)
|
Find(&teams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserTeamIDs returns of all team IDs of the organization that user is member of.
|
func (org *User) getUserTeamIDs(e Engine, userID int64) ([]int64, error) {
|
||||||
func (org *User) GetUserTeamIDs(userID int64) ([]int64, error) {
|
teamIDs := make([]int64, 0, org.NumTeams)
|
||||||
teams, err := org.getUserTeams(x, userID, "team.id")
|
return teamIDs, e.
|
||||||
if err != nil {
|
Table("team").
|
||||||
return nil, fmt.Errorf("getUserTeams [%d]: %v", userID, err)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
teamIDs := make([]int64, len(teams))
|
// GetUserTeamIDs returns of all team IDs of the organization that user is member of.
|
||||||
for i := range teams {
|
func (org *User) GetUserTeamIDs(userID int64) ([]int64, error) {
|
||||||
teamIDs[i] = teams[i].ID
|
return org.getUserTeamIDs(x, userID)
|
||||||
}
|
|
||||||
return teamIDs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserTeams returns all teams that belong to user,
|
// GetUserTeams returns all teams that belong to user,
|
||||||
|
|
Reference in a new issue