@@ -9,6 +9,11 @@ import "fmt"
9
9
// IssueList defines a list of issues
10
10
type IssueList []* Issue
11
11
12
+ const (
13
+ // default variables number on IN () in SQL
14
+ defaultMaxInSize = 50
15
+ )
16
+
12
17
func (issues IssueList ) getRepoIDs () []int64 {
13
18
repoIDs := make (map [int64 ]struct {}, len (issues ))
14
19
for _ , issue := range issues {
@@ -26,11 +31,20 @@ func (issues IssueList) loadRepositories(e Engine) ([]*Repository, error) {
26
31
27
32
repoIDs := issues .getRepoIDs ()
28
33
repoMaps := make (map [int64 ]* Repository , len (repoIDs ))
29
- err := e .
30
- In ("id" , repoIDs ).
31
- Find (& repoMaps )
32
- if err != nil {
33
- return nil , fmt .Errorf ("find repository: %v" , err )
34
+ var left = len (repoIDs )
35
+ for left > 0 {
36
+ var limit = defaultMaxInSize
37
+ if left < limit {
38
+ limit = left
39
+ }
40
+ err := e .
41
+ In ("id" , repoIDs [:limit ]).
42
+ Find (& repoMaps )
43
+ if err != nil {
44
+ return nil , fmt .Errorf ("find repository: %v" , err )
45
+ }
46
+ left = left - limit
47
+ repoIDs = repoIDs [limit :]
34
48
}
35
49
36
50
for _ , issue := range issues {
@@ -61,11 +75,20 @@ func (issues IssueList) loadPosters(e Engine) error {
61
75
62
76
posterIDs := issues .getPosterIDs ()
63
77
posterMaps := make (map [int64 ]* User , len (posterIDs ))
64
- err := e .
65
- In ("id" , posterIDs ).
66
- Find (& posterMaps )
67
- if err != nil {
68
- return err
78
+ var left = len (posterIDs )
79
+ for left > 0 {
80
+ var limit = defaultMaxInSize
81
+ if left < limit {
82
+ limit = left
83
+ }
84
+ err := e .
85
+ In ("id" , posterIDs [:limit ]).
86
+ Find (& posterMaps )
87
+ if err != nil {
88
+ return err
89
+ }
90
+ left = left - limit
91
+ posterIDs = posterIDs [limit :]
69
92
}
70
93
71
94
for _ , issue := range issues {
@@ -99,23 +122,34 @@ func (issues IssueList) loadLabels(e Engine) error {
99
122
}
100
123
101
124
var issueLabels = make (map [int64 ][]* Label , len (issues )* 3 )
102
- rows , err := e .Table ("label" ).
103
- Join ("LEFT" , "issue_label" , "issue_label.label_id = label.id" ).
104
- In ("issue_label.issue_id" , issues .getIssueIDs ()).
105
- Asc ("label.name" ).
106
- Rows (new (LabelIssue ))
107
- if err != nil {
108
- return err
109
- }
110
- defer rows .Close ()
111
-
112
- for rows .Next () {
113
- var labelIssue LabelIssue
114
- err = rows .Scan (& labelIssue )
125
+ var issueIDs = issues .getIssueIDs ()
126
+ var left = len (issueIDs )
127
+ for left > 0 {
128
+ var limit = defaultMaxInSize
129
+ if left < limit {
130
+ limit = left
131
+ }
132
+ rows , err := e .Table ("label" ).
133
+ Join ("LEFT" , "issue_label" , "issue_label.label_id = label.id" ).
134
+ In ("issue_label.issue_id" , issueIDs [:limit ]).
135
+ Asc ("label.name" ).
136
+ Rows (new (LabelIssue ))
115
137
if err != nil {
116
138
return err
117
139
}
118
- issueLabels [labelIssue .IssueLabel .IssueID ] = append (issueLabels [labelIssue .IssueLabel .IssueID ], labelIssue .Label )
140
+
141
+ for rows .Next () {
142
+ var labelIssue LabelIssue
143
+ err = rows .Scan (& labelIssue )
144
+ if err != nil {
145
+ rows .Close ()
146
+ return err
147
+ }
148
+ issueLabels [labelIssue .IssueLabel .IssueID ] = append (issueLabels [labelIssue .IssueLabel .IssueID ], labelIssue .Label )
149
+ }
150
+ rows .Close ()
151
+ left = left - limit
152
+ issueIDs = issueIDs [limit :]
119
153
}
120
154
121
155
for _ , issue := range issues {
@@ -141,11 +175,20 @@ func (issues IssueList) loadMilestones(e Engine) error {
141
175
}
142
176
143
177
milestoneMaps := make (map [int64 ]* Milestone , len (milestoneIDs ))
144
- err := e .
145
- In ("id" , milestoneIDs ).
146
- Find (& milestoneMaps )
147
- if err != nil {
148
- return err
178
+ var left = len (milestoneIDs )
179
+ for left > 0 {
180
+ var limit = defaultMaxInSize
181
+ if left < limit {
182
+ limit = left
183
+ }
184
+ err := e .
185
+ In ("id" , milestoneIDs [:limit ]).
186
+ Find (& milestoneMaps )
187
+ if err != nil {
188
+ return err
189
+ }
190
+ left = left - limit
191
+ milestoneIDs = milestoneIDs [limit :]
149
192
}
150
193
151
194
for _ , issue := range issues {
@@ -165,23 +208,35 @@ func (issues IssueList) loadAssignees(e Engine) error {
165
208
}
166
209
167
210
var assignees = make (map [int64 ][]* User , len (issues ))
168
- rows , err := e .Table ("issue_assignees" ).
169
- Join ("INNER" , "`user`" , "`user`.id = `issue_assignees`.assignee_id" ).
170
- In ("`issue_assignees`.issue_id" , issues .getIssueIDs ()).
171
- Rows (new (AssigneeIssue ))
172
- if err != nil {
173
- return err
174
- }
175
- defer rows .Close ()
176
-
177
- for rows .Next () {
178
- var assigneeIssue AssigneeIssue
179
- err = rows .Scan (& assigneeIssue )
211
+ var issueIDs = issues .getIssueIDs ()
212
+ var left = len (issueIDs )
213
+ for left > 0 {
214
+ var limit = defaultMaxInSize
215
+ if left < limit {
216
+ limit = left
217
+ }
218
+ rows , err := e .Table ("issue_assignees" ).
219
+ Join ("INNER" , "`user`" , "`user`.id = `issue_assignees`.assignee_id" ).
220
+ In ("`issue_assignees`.issue_id" , issueIDs [:limit ]).
221
+ Rows (new (AssigneeIssue ))
180
222
if err != nil {
181
223
return err
182
224
}
183
225
184
- assignees [assigneeIssue .IssueAssignee .IssueID ] = append (assignees [assigneeIssue .IssueAssignee .IssueID ], assigneeIssue .Assignee )
226
+ for rows .Next () {
227
+ var assigneeIssue AssigneeIssue
228
+ err = rows .Scan (& assigneeIssue )
229
+ if err != nil {
230
+ rows .Close ()
231
+ return err
232
+ }
233
+
234
+ assignees [assigneeIssue .IssueAssignee .IssueID ] = append (assignees [assigneeIssue .IssueAssignee .IssueID ], assigneeIssue .Assignee )
235
+ }
236
+ rows .Close ()
237
+
238
+ left = left - limit
239
+ issueIDs = issueIDs [limit :]
185
240
}
186
241
187
242
for _ , issue := range issues {
@@ -207,21 +262,32 @@ func (issues IssueList) loadPullRequests(e Engine) error {
207
262
}
208
263
209
264
pullRequestMaps := make (map [int64 ]* PullRequest , len (issuesIDs ))
210
- rows , err := e .
211
- In ("issue_id" , issuesIDs ).
212
- Rows (new (PullRequest ))
213
- if err != nil {
214
- return err
215
- }
216
- defer rows .Close ()
217
-
218
- for rows .Next () {
219
- var pr PullRequest
220
- err = rows .Scan (& pr )
265
+ var left = len (issuesIDs )
266
+ for left > 0 {
267
+ var limit = defaultMaxInSize
268
+ if left < limit {
269
+ limit = left
270
+ }
271
+ rows , err := e .
272
+ In ("issue_id" , issuesIDs [:limit ]).
273
+ Rows (new (PullRequest ))
221
274
if err != nil {
222
275
return err
223
276
}
224
- pullRequestMaps [pr .IssueID ] = & pr
277
+
278
+ for rows .Next () {
279
+ var pr PullRequest
280
+ err = rows .Scan (& pr )
281
+ if err != nil {
282
+ rows .Close ()
283
+ return err
284
+ }
285
+ pullRequestMaps [pr .IssueID ] = & pr
286
+ }
287
+
288
+ rows .Close ()
289
+ left = left - limit
290
+ issuesIDs = issuesIDs [limit :]
225
291
}
226
292
227
293
for _ , issue := range issues {
@@ -236,22 +302,34 @@ func (issues IssueList) loadAttachments(e Engine) (err error) {
236
302
}
237
303
238
304
var attachments = make (map [int64 ][]* Attachment , len (issues ))
239
- rows , err := e .Table ("attachment" ).
240
- Join ("INNER" , "issue" , "issue.id = attachment.issue_id" ).
241
- In ("issue.id" , issues .getIssueIDs ()).
242
- Rows (new (Attachment ))
243
- if err != nil {
244
- return err
245
- }
246
- defer rows .Close ()
247
-
248
- for rows .Next () {
249
- var attachment Attachment
250
- err = rows .Scan (& attachment )
305
+ var issuesIDs = issues .getIssueIDs ()
306
+ var left = len (issuesIDs )
307
+ for left > 0 {
308
+ var limit = defaultMaxInSize
309
+ if left < limit {
310
+ limit = left
311
+ }
312
+ rows , err := e .Table ("attachment" ).
313
+ Join ("INNER" , "issue" , "issue.id = attachment.issue_id" ).
314
+ In ("issue.id" , issuesIDs [:limit ]).
315
+ Rows (new (Attachment ))
251
316
if err != nil {
252
317
return err
253
318
}
254
- attachments [attachment .IssueID ] = append (attachments [attachment .IssueID ], & attachment )
319
+
320
+ for rows .Next () {
321
+ var attachment Attachment
322
+ err = rows .Scan (& attachment )
323
+ if err != nil {
324
+ rows .Close ()
325
+ return err
326
+ }
327
+ attachments [attachment .IssueID ] = append (attachments [attachment .IssueID ], & attachment )
328
+ }
329
+
330
+ rows .Close ()
331
+ left = left - limit
332
+ issuesIDs = issuesIDs [limit :]
255
333
}
256
334
257
335
for _ , issue := range issues {
@@ -266,22 +344,33 @@ func (issues IssueList) loadComments(e Engine) (err error) {
266
344
}
267
345
268
346
var comments = make (map [int64 ][]* Comment , len (issues ))
269
- rows , err := e .Table ("comment" ).
270
- Join ("INNER" , "issue" , "issue.id = comment.issue_id" ).
271
- In ("issue.id" , issues .getIssueIDs ()).
272
- Rows (new (Comment ))
273
- if err != nil {
274
- return err
275
- }
276
- defer rows .Close ()
277
-
278
- for rows .Next () {
279
- var comment Comment
280
- err = rows .Scan (& comment )
347
+ var issuesIDs = issues .getIssueIDs ()
348
+ var left = len (issuesIDs )
349
+ for left > 0 {
350
+ var limit = defaultMaxInSize
351
+ if left < limit {
352
+ limit = left
353
+ }
354
+ rows , err := e .Table ("comment" ).
355
+ Join ("INNER" , "issue" , "issue.id = comment.issue_id" ).
356
+ In ("issue.id" , issuesIDs [:limit ]).
357
+ Rows (new (Comment ))
281
358
if err != nil {
282
359
return err
283
360
}
284
- comments [comment .IssueID ] = append (comments [comment .IssueID ], & comment )
361
+
362
+ for rows .Next () {
363
+ var comment Comment
364
+ err = rows .Scan (& comment )
365
+ if err != nil {
366
+ rows .Close ()
367
+ return err
368
+ }
369
+ comments [comment .IssueID ] = append (comments [comment .IssueID ], & comment )
370
+ }
371
+ rows .Close ()
372
+ left = left - limit
373
+ issuesIDs = issuesIDs [limit :]
285
374
}
286
375
287
376
for _ , issue := range issues {
@@ -307,25 +396,35 @@ func (issues IssueList) loadTotalTrackedTimes(e Engine) (err error) {
307
396
}
308
397
}
309
398
310
- // select issue_id, sum(time) from tracked_time where issue_id in (<issue ids in current page>) group by issue_id
311
- rows , err := e .Table ("tracked_time" ).
312
- Select ("issue_id, sum(time) as time" ).
313
- In ("issue_id" , ids ).
314
- GroupBy ("issue_id" ).
315
- Rows (new (totalTimesByIssue ))
316
- if err != nil {
317
- return err
318
- }
319
-
320
- defer rows .Close ()
399
+ var left = len (ids )
400
+ for left > 0 {
401
+ var limit = defaultMaxInSize
402
+ if left < limit {
403
+ limit = left
404
+ }
321
405
322
- for rows .Next () {
323
- var totalTime totalTimesByIssue
324
- err = rows .Scan (& totalTime )
406
+ // select issue_id, sum(time) from tracked_time where issue_id in (<issue ids in current page>) group by issue_id
407
+ rows , err := e .Table ("tracked_time" ).
408
+ Select ("issue_id, sum(time) as time" ).
409
+ In ("issue_id" , ids [:limit ]).
410
+ GroupBy ("issue_id" ).
411
+ Rows (new (totalTimesByIssue ))
325
412
if err != nil {
326
413
return err
327
414
}
328
- trackedTimes [totalTime .IssueID ] = totalTime .Time
415
+
416
+ for rows .Next () {
417
+ var totalTime totalTimesByIssue
418
+ err = rows .Scan (& totalTime )
419
+ if err != nil {
420
+ rows .Close ()
421
+ return err
422
+ }
423
+ trackedTimes [totalTime .IssueID ] = totalTime .Time
424
+ }
425
+ rows .Close ()
426
+ left = left - limit
427
+ ids = ids [limit :]
329
428
}
330
429
331
430
for _ , issue := range issues {
0 commit comments