@@ -120,10 +120,12 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
120
120
opts .Page = 1
121
121
}
122
122
123
+ var starJoin bool
123
124
if opts .Starred && opts .OwnerID > 0 {
124
125
cond = builder.Eq {
125
126
"star.uid" : opts .OwnerID ,
126
127
}
128
+ starJoin = true
127
129
}
128
130
129
131
opts .Keyword = strings .ToLower (opts .Keyword )
@@ -133,42 +135,42 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
133
135
134
136
// Append conditions
135
137
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 )
137
160
}
161
+
138
162
if ! opts .Private {
139
163
cond = cond .And (builder.Eq {"is_private" : false })
140
164
}
141
165
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
-
164
166
if len (opts .OrderBy ) == 0 {
165
167
opts .OrderBy = "name ASC"
166
168
}
167
169
168
170
sess := x .NewSession ()
169
171
defer sess .Close ()
170
172
171
- if opts . Starred && opts . OwnerID > 0 {
173
+ if starJoin {
172
174
count , err = sess .
173
175
Join ("INNER" , "star" , "star.repo_id = repository.id" ).
174
176
Where (cond ).
0 commit comments