@@ -536,24 +536,28 @@ func (org *User) GetUserTeams(userID int64) ([]*Team, error) {
536
536
// that the user with the given userID has access to,
537
537
// and total number of records based on given condition.
538
538
func (org * User ) GetUserRepositories (userID int64 , page , pageSize int ) ([]* Repository , int64 , error ) {
539
+ var cond builder.Cond = builder.Eq {
540
+ "`repository`.owner_id" : org .ID ,
541
+ "`repository`.is_private" : false ,
542
+ }
543
+
539
544
teamIDs , err := org .GetUserTeamIDs (userID )
540
545
if err != nil {
541
546
return nil , 0 , fmt .Errorf ("GetUserTeamIDs: %v" , err )
542
547
}
543
- if len ( teamIDs ) == 0 {
544
- // user has no team but "IN ()" is invalid SQL
545
- teamIDs = [] int64 { - 1 } // there is no repo with id=-1
548
+
549
+ if len ( teamIDs ) > 0 {
550
+ cond = cond . Or ( builder . In ( "team_repo.team_id" , teamIDs ))
546
551
}
547
552
548
553
if page <= 0 {
549
554
page = 1
550
555
}
551
556
repos := make ([]* Repository , 0 , pageSize )
557
+
552
558
if err := x .
553
- Select ("`repository`.*" ).
554
559
Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id" ).
555
- Where ("(`repository`.owner_id=? AND `repository`.is_private=?)" , org .ID , false ).
556
- Or (builder .In ("team_repo.team_id" , teamIDs )).
560
+ Where (cond ).
557
561
GroupBy ("`repository`.id" ).
558
562
OrderBy ("updated_unix DESC" ).
559
563
Limit (pageSize , (page - 1 )* pageSize ).
@@ -563,8 +567,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
563
567
564
568
repoCount , err := x .
565
569
Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id" ).
566
- Where ("(`repository`.owner_id=? AND `repository`.is_private=?)" , org .ID , false ).
567
- Or (builder .In ("team_repo.team_id" , teamIDs )).
570
+ Where (cond ).
568
571
GroupBy ("`repository`.id" ).
569
572
Count (& Repository {})
570
573
if err != nil {
0 commit comments