@@ -281,9 +281,9 @@ func (nl NotificationList) getPendingRepoIDs() []int64 {
281
281
}
282
282
283
283
// LoadRepos loads repositories from database
284
- func (nl NotificationList ) LoadRepos () (RepositoryList , error ) {
284
+ func (nl NotificationList ) LoadRepos () (RepositoryList , [] int , error ) {
285
285
if len (nl ) == 0 {
286
- return RepositoryList {}, nil
286
+ return RepositoryList {}, [] int {}, nil
287
287
}
288
288
289
289
var repoIDs = nl .getPendingRepoIDs ()
@@ -298,15 +298,15 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
298
298
In ("id" , repoIDs [:limit ]).
299
299
Rows (new (Repository ))
300
300
if err != nil {
301
- return nil , err
301
+ return nil , nil , err
302
302
}
303
303
304
304
for rows .Next () {
305
305
var repo Repository
306
306
err = rows .Scan (& repo )
307
307
if err != nil {
308
308
rows .Close ()
309
- return nil , err
309
+ return nil , nil , err
310
310
}
311
311
312
312
repos [repo .ID ] = & repo
@@ -317,14 +317,21 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
317
317
repoIDs = repoIDs [limit :]
318
318
}
319
319
320
+ failed := []int {}
321
+
320
322
var reposList = make (RepositoryList , 0 , len (repoIDs ))
321
- for _ , notification := range nl {
323
+ for i , notification := range nl {
322
324
if notification .Repository == nil {
323
325
notification .Repository = repos [notification .RepoID ]
324
326
}
327
+ if notification .Repository == nil {
328
+ log .Error ("Notification[%d]: RepoID: %d not found" , notification .ID , notification .RepoID )
329
+ failed = append (failed , i )
330
+ continue
331
+ }
325
332
var found bool
326
333
for _ , r := range reposList {
327
- if r .ID == notification .Repository . ID {
334
+ if r .ID == notification .RepoID {
328
335
found = true
329
336
break
330
337
}
@@ -333,7 +340,7 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
333
340
reposList = append (reposList , notification .Repository )
334
341
}
335
342
}
336
- return reposList , nil
343
+ return reposList , failed , nil
337
344
}
338
345
339
346
func (nl NotificationList ) getPendingIssueIDs () []int64 {
@@ -350,9 +357,9 @@ func (nl NotificationList) getPendingIssueIDs() []int64 {
350
357
}
351
358
352
359
// LoadIssues loads issues from database
353
- func (nl NotificationList ) LoadIssues () error {
360
+ func (nl NotificationList ) LoadIssues () ([] int , error ) {
354
361
if len (nl ) == 0 {
355
- return nil
362
+ return [] int {}, nil
356
363
}
357
364
358
365
var issueIDs = nl .getPendingIssueIDs ()
@@ -367,15 +374,15 @@ func (nl NotificationList) LoadIssues() error {
367
374
In ("id" , issueIDs [:limit ]).
368
375
Rows (new (Issue ))
369
376
if err != nil {
370
- return err
377
+ return nil , err
371
378
}
372
379
373
380
for rows .Next () {
374
381
var issue Issue
375
382
err = rows .Scan (& issue )
376
383
if err != nil {
377
384
rows .Close ()
378
- return err
385
+ return nil , err
379
386
}
380
387
381
388
issues [issue .ID ] = & issue
@@ -386,13 +393,38 @@ func (nl NotificationList) LoadIssues() error {
386
393
issueIDs = issueIDs [limit :]
387
394
}
388
395
389
- for _ , notification := range nl {
396
+ failures := []int {}
397
+
398
+ for i , notification := range nl {
390
399
if notification .Issue == nil {
391
400
notification .Issue = issues [notification .IssueID ]
401
+ if notification .Issue == nil {
402
+ log .Error ("Notification[%d]: IssueID: %d Not Found" , notification .ID , notification .IssueID )
403
+ failures = append (failures , i )
404
+ continue
405
+ }
392
406
notification .Issue .Repo = notification .Repository
393
407
}
394
408
}
395
- return nil
409
+ return failures , nil
410
+ }
411
+
412
+ // Without returns the notification list without the failures
413
+ func (nl NotificationList ) Without (failures []int ) NotificationList {
414
+ if failures == nil || len (failures ) == 0 {
415
+ return nl
416
+ }
417
+ remaining := make ([]* Notification , 0 , len (nl ))
418
+ last := - 1
419
+ var i int
420
+ for _ , i = range failures {
421
+ remaining = append (remaining , nl [last + 1 :i ]... )
422
+ last = i
423
+ }
424
+ if len (nl ) > i {
425
+ remaining = append (remaining , nl [i + 1 :]... )
426
+ }
427
+ return remaining
396
428
}
397
429
398
430
func (nl NotificationList ) getPendingCommentIDs () []int64 {
@@ -409,9 +441,9 @@ func (nl NotificationList) getPendingCommentIDs() []int64 {
409
441
}
410
442
411
443
// LoadComments loads comments from database
412
- func (nl NotificationList ) LoadComments () error {
444
+ func (nl NotificationList ) LoadComments () ([] int , error ) {
413
445
if len (nl ) == 0 {
414
- return nil
446
+ return [] int {}, nil
415
447
}
416
448
417
449
var commentIDs = nl .getPendingCommentIDs ()
@@ -426,15 +458,15 @@ func (nl NotificationList) LoadComments() error {
426
458
In ("id" , commentIDs [:limit ]).
427
459
Rows (new (Comment ))
428
460
if err != nil {
429
- return err
461
+ return nil , err
430
462
}
431
463
432
464
for rows .Next () {
433
465
var comment Comment
434
466
err = rows .Scan (& comment )
435
467
if err != nil {
436
468
rows .Close ()
437
- return err
469
+ return nil , err
438
470
}
439
471
440
472
comments [comment .ID ] = & comment
@@ -445,13 +477,19 @@ func (nl NotificationList) LoadComments() error {
445
477
commentIDs = commentIDs [limit :]
446
478
}
447
479
448
- for _ , notification := range nl {
480
+ failures := []int {}
481
+ for i , notification := range nl {
449
482
if notification .CommentID > 0 && notification .Comment == nil && comments [notification .CommentID ] != nil {
450
483
notification .Comment = comments [notification .CommentID ]
484
+ if notification .Comment == nil {
485
+ log .Error ("Notification[%d]: CommentID[%d] failed to load" , notification .ID , notification .CommentID )
486
+ failures = append (failures , i )
487
+ continue
488
+ }
451
489
notification .Comment .Issue = notification .Issue
452
490
}
453
491
}
454
- return nil
492
+ return failures , nil
455
493
}
456
494
457
495
// GetNotificationCount returns the notification count for user
0 commit comments