@@ -120,10 +120,12 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
120120 opts .Page = 1
121121 }
122122
123+ var starJoin bool
123124 if opts .Starred && opts .OwnerID > 0 {
124125 cond = builder.Eq {
125126 "star.uid" : opts .OwnerID ,
126127 }
128+ starJoin = true
127129 }
128130
129131 opts .Keyword = strings .ToLower (opts .Keyword )
@@ -133,42 +135,42 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
133135
134136 // Append conditions
135137 if ! opts .Starred && opts .OwnerID > 0 {
136- cond = cond .And (builder.Eq {"owner_id" : opts .OwnerID })
138+ var searcherReposCond builder.Cond = builder.Eq {"owner_id" : opts .OwnerID }
139+ if opts .Searcher != nil {
140+ var ownerIds []int64
141+
142+ ownerIds = append (ownerIds , opts .Searcher .ID )
143+ err = opts .Searcher .GetOrganizations (true )
144+
145+ if err != nil {
146+ return nil , 0 , fmt .Errorf ("Organization: %v" , err )
147+ }
148+
149+ for _ , org := range opts .Searcher .Orgs {
150+ ownerIds = append (ownerIds , org .ID )
151+ }
152+
153+ searcherReposCond = searcherReposCond .Or (builder .In ("owner_id" , ownerIds ))
154+ if opts .Collaborate {
155+ searcherReposCond = searcherReposCond .Or (builder .Expr ("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ? AND owner_id != ?)" ,
156+ opts .Searcher .ID , opts .Searcher .ID ))
157+ }
158+ }
159+ cond = cond .And (searcherReposCond )
137160 }
161+
138162 if ! opts .Private {
139163 cond = cond .And (builder.Eq {"is_private" : false })
140164 }
141165
142- if opts .Searcher != nil {
143- var ownerIds []int64
144-
145- ownerIds = append (ownerIds , opts .Searcher .ID )
146- err = opts .Searcher .GetOrganizations (true )
147-
148- if err != nil {
149- return nil , 0 , fmt .Errorf ("Organization: %v" , err )
150- }
151-
152- for _ , org := range opts .Searcher .Orgs {
153- ownerIds = append (ownerIds , org .ID )
154- }
155-
156- searcherReposCond := builder .In ("owner_id" , ownerIds )
157- if opts .Collaborate {
158- searcherReposCond = searcherReposCond .Or (builder .Expr (`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)` ,
159- opts .Searcher .ID , opts .Searcher .ID ))
160- }
161- cond = cond .And (searcherReposCond )
162- }
163-
164166 if len (opts .OrderBy ) == 0 {
165167 opts .OrderBy = "name ASC"
166168 }
167169
168170 sess := x .NewSession ()
169171 defer sess .Close ()
170172
171- if opts . Starred && opts . OwnerID > 0 {
173+ if starJoin {
172174 count , err = sess .
173175 Join ("INNER" , "star" , "star.repo_id = repository.id" ).
174176 Where (cond ).
0 commit comments