@@ -93,7 +93,6 @@ func SearchIssues(ctx *context.APIContext) {
93
93
opts .AllLimited = true
94
94
}
95
95
96
- issueCount := 0
97
96
for page := 1 ; ; page ++ {
98
97
opts .Page = page
99
98
repos , count , err := models .SearchRepositoryByName (opts )
@@ -107,19 +106,12 @@ func SearchIssues(ctx *context.APIContext) {
107
106
}
108
107
log .Trace ("Processing next %d repos of %d" , len (repos ), count )
109
108
for _ , repo := range repos {
110
- switch isClosed {
111
- case util .OptionalBoolTrue :
112
- issueCount += repo .NumClosedIssues
113
- case util .OptionalBoolFalse :
114
- issueCount += repo .NumOpenIssues
115
- case util .OptionalBoolNone :
116
- issueCount += repo .NumIssues
117
- }
118
109
repoIDs = append (repoIDs , repo .ID )
119
110
}
120
111
}
121
112
122
113
var issues []* models.Issue
114
+ var filteredCount int64
123
115
124
116
keyword := strings .Trim (ctx .Query ("q" ), " " )
125
117
if strings .IndexByte (keyword , 0 ) >= 0 {
@@ -129,7 +121,10 @@ func SearchIssues(ctx *context.APIContext) {
129
121
var labelIDs []int64
130
122
var err error
131
123
if len (keyword ) > 0 && len (repoIDs ) > 0 {
132
- issueIDs , err = issue_indexer .SearchIssuesByKeyword (repoIDs , keyword )
124
+ if issueIDs , err = issue_indexer .SearchIssuesByKeyword (repoIDs , keyword ); err != nil {
125
+ ctx .Error (http .StatusInternalServerError , "SearchIssuesByKeyword" , err )
126
+ return
127
+ }
133
128
}
134
129
135
130
var isPull util.OptionalBool
@@ -151,29 +146,36 @@ func SearchIssues(ctx *context.APIContext) {
151
146
// Only fetch the issues if we either don't have a keyword or the search returned issues
152
147
// This would otherwise return all issues if no issues were found by the search.
153
148
if len (keyword ) == 0 || len (issueIDs ) > 0 || len (labelIDs ) > 0 {
154
- issues , err = models . Issues ( & models.IssuesOptions {
149
+ issuesOpt := & models.IssuesOptions {
155
150
ListOptions : models.ListOptions {
156
151
Page : ctx .QueryInt ("page" ),
157
152
PageSize : setting .UI .IssuePagingNum ,
158
153
},
159
-
160
154
RepoIDs : repoIDs ,
161
155
IsClosed : isClosed ,
162
156
IssueIDs : issueIDs ,
163
157
IncludedLabelNames : includedLabelNames ,
164
158
SortType : "priorityrepo" ,
165
159
PriorityRepoID : ctx .QueryInt64 ("priority_repo_id" ),
166
160
IsPull : isPull ,
167
- })
168
- }
161
+ }
169
162
170
- if err != nil {
171
- ctx .Error (http .StatusInternalServerError , "Issues" , err )
172
- return
163
+ if issues , err = models .Issues (issuesOpt ); err != nil {
164
+ ctx .Error (http .StatusInternalServerError , "Issues" , err )
165
+ return
166
+ }
167
+
168
+ issuesOpt .ListOptions = models.ListOptions {
169
+ Page : - 1 ,
170
+ }
171
+ if filteredCount , err = models .CountIssues (issuesOpt ); err != nil {
172
+ ctx .Error (http .StatusInternalServerError , "CountIssues" , err )
173
+ return
174
+ }
173
175
}
174
176
175
- ctx .SetLinkHeader (issueCount , setting .UI .IssuePagingNum )
176
- ctx .Header ().Set ("X-Total-Count" , fmt .Sprintf ("%d" , issueCount ))
177
+ ctx .SetLinkHeader (int ( filteredCount ) , setting .UI .IssuePagingNum )
178
+ ctx .Header ().Set ("X-Total-Count" , fmt .Sprintf ("%d" , filteredCount ))
177
179
ctx .Header ().Set ("Access-Control-Expose-Headers" , "X-Total-Count, Link" )
178
180
ctx .JSON (http .StatusOK , convert .ToAPIIssueList (issues ))
179
181
}
@@ -241,6 +243,7 @@ func ListIssues(ctx *context.APIContext) {
241
243
}
242
244
243
245
var issues []* models.Issue
246
+ var filteredCount int64
244
247
245
248
keyword := strings .Trim (ctx .Query ("q" ), " " )
246
249
if strings .IndexByte (keyword , 0 ) >= 0 {
@@ -251,6 +254,10 @@ func ListIssues(ctx *context.APIContext) {
251
254
var err error
252
255
if len (keyword ) > 0 {
253
256
issueIDs , err = issue_indexer .SearchIssuesByKeyword ([]int64 {ctx .Repo .Repository .ID }, keyword )
257
+ if err != nil {
258
+ ctx .Error (http .StatusInternalServerError , "SearchIssuesByKeyword" , err )
259
+ return
260
+ }
254
261
}
255
262
256
263
if splitted := strings .Split (ctx .Query ("labels" ), "," ); len (splitted ) > 0 {
@@ -306,26 +313,33 @@ func ListIssues(ctx *context.APIContext) {
306
313
// Only fetch the issues if we either don't have a keyword or the search returned issues
307
314
// This would otherwise return all issues if no issues were found by the search.
308
315
if len (keyword ) == 0 || len (issueIDs ) > 0 || len (labelIDs ) > 0 {
309
- issues , err = models . Issues ( & models.IssuesOptions {
316
+ issuesOpt := & models.IssuesOptions {
310
317
ListOptions : listOptions ,
311
318
RepoIDs : []int64 {ctx .Repo .Repository .ID },
312
319
IsClosed : isClosed ,
313
320
IssueIDs : issueIDs ,
314
321
LabelIDs : labelIDs ,
315
322
MilestoneIDs : mileIDs ,
316
323
IsPull : isPull ,
317
- })
318
- }
324
+ }
319
325
320
- if err != nil {
321
- ctx .Error (http .StatusInternalServerError , "Issues" , err )
322
- return
326
+ if issues , err = models .Issues (issuesOpt ); err != nil {
327
+ ctx .Error (http .StatusInternalServerError , "Issues" , err )
328
+ return
329
+ }
330
+
331
+ issuesOpt .ListOptions = models.ListOptions {
332
+ Page : - 1 ,
333
+ }
334
+ if filteredCount , err = models .CountIssues (issuesOpt ); err != nil {
335
+ ctx .Error (http .StatusInternalServerError , "CountIssues" , err )
336
+ return
337
+ }
323
338
}
324
339
325
- ctx .SetLinkHeader (ctx . Repo . Repository . NumIssues , listOptions .PageSize )
326
- ctx .Header ().Set ("X-Total-Count" , fmt .Sprintf ("%d" , ctx . Repo . Repository . NumIssues ))
340
+ ctx .SetLinkHeader (int ( filteredCount ) , listOptions .PageSize )
341
+ ctx .Header ().Set ("X-Total-Count" , fmt .Sprintf ("%d" , filteredCount ))
327
342
ctx .Header ().Set ("Access-Control-Expose-Headers" , "X-Total-Count, Link" )
328
-
329
343
ctx .JSON (http .StatusOK , convert .ToAPIIssueList (issues ))
330
344
}
331
345
0 commit comments