@@ -1054,11 +1054,10 @@ func RemoveOrgRepo(orgID, repoID int64) error {
1054
1054
// GetUserRepositories gets all repositories of an organization,
1055
1055
// that the user with the given userID has access to.
1056
1056
func (org * User ) GetUserRepositories (userID int64 ) (err error ) {
1057
- teams := make ([]* Team , 0 , 10 )
1058
- if err = x .Where ("`team_user`.org_id=?" , org .Id ).
1059
- And ("`team_user`.uid=?" , userID ).
1060
- Join ("INNER" , "`team_user`" , "`team_user`.team_id=`team`.id" ).
1061
- Find (& teams ); err != nil {
1057
+ teams := make ([]* Team , 0 , org .NumTeams )
1058
+ if err = x .Sql (`SELECT team.id FROM team
1059
+ INNER JOIN team_user ON team_user.team_id = team.id
1060
+ WHERE team_user.org_id = ? AND team_user.uid = ?` , org .Id , userID ).Find (& teams ); err != nil {
1062
1061
return fmt .Errorf ("get teams: %v" , err )
1063
1062
}
1064
1063
@@ -1071,18 +1070,15 @@ func (org *User) GetUserRepositories(userID int64) (err error) {
1071
1070
teamIDs = append (teamIDs , "-1" ) // there is no repo with id=-1
1072
1071
}
1073
1072
1074
- // Due to a bug in xorm using IN() together with OR() is impossible.
1075
- // As a workaround, we have to build the IN statement on our own, until this is fixed.
1076
- // https://github.com/go-xorm/xorm/issues/342
1077
-
1078
- if err = x .Join ("INNER" , "`team_repo`" , "`team_repo`.repo_id=`repository`.id" ).
1079
- Where ("`repository`.owner_id=?" , org .Id ).
1080
- And ("`repository`.is_private=?" , false ).
1081
- Or ("`team_repo`.team_id IN (?)" , strings .Join (teamIDs , "," )).
1082
- GroupBy ("`repository`.id" ).
1083
- Find (& org .Repos ); err != nil {
1073
+ repos := make ([]* Repository , 0 , 5 )
1074
+ if err = x .Sql (`SELECT repository.* FROM repository
1075
+ INNER JOIN team_repo ON team_repo.repo_id = repository.id
1076
+ WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (?)
1077
+ GROUP BY repository.id` ,
1078
+ org .Id , false , strings .Join (teamIDs , "," )).Find (& repos ); err != nil {
1084
1079
return fmt .Errorf ("get repositories: %v" , err )
1085
1080
}
1081
+ org .Repos = repos
1086
1082
1087
1083
// FIXME: should I change this value inside method,
1088
1084
// or only in location of caller where it's really needed?
0 commit comments