@@ -481,9 +481,9 @@ func (nl NotificationList) getPendingRepoIDs() []int64 {
481
481
}
482
482
483
483
// LoadRepos loads repositories from database
484
- func (nl NotificationList ) LoadRepos () (RepositoryList , error ) {
484
+ func (nl NotificationList ) LoadRepos () (RepositoryList , [] int , error ) {
485
485
if len (nl ) == 0 {
486
- return RepositoryList {}, nil
486
+ return RepositoryList {}, [] int {}, nil
487
487
}
488
488
489
489
var repoIDs = nl .getPendingRepoIDs ()
@@ -498,15 +498,15 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
498
498
In ("id" , repoIDs [:limit ]).
499
499
Rows (new (Repository ))
500
500
if err != nil {
501
- return nil , err
501
+ return nil , nil , err
502
502
}
503
503
504
504
for rows .Next () {
505
505
var repo Repository
506
506
err = rows .Scan (& repo )
507
507
if err != nil {
508
508
rows .Close ()
509
- return nil , err
509
+ return nil , nil , err
510
510
}
511
511
512
512
repos [repo .ID ] = & repo
@@ -517,14 +517,21 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
517
517
repoIDs = repoIDs [limit :]
518
518
}
519
519
520
+ failed := []int {}
521
+
520
522
var reposList = make (RepositoryList , 0 , len (repoIDs ))
521
- for _ , notification := range nl {
523
+ for i , notification := range nl {
522
524
if notification .Repository == nil {
523
525
notification .Repository = repos [notification .RepoID ]
524
526
}
527
+ if notification .Repository == nil {
528
+ log .Error ("Notification[%d]: RepoID: %d not found" , notification .ID , notification .RepoID )
529
+ failed = append (failed , i )
530
+ continue
531
+ }
525
532
var found bool
526
533
for _ , r := range reposList {
527
- if r .ID == notification .Repository . ID {
534
+ if r .ID == notification .RepoID {
528
535
found = true
529
536
break
530
537
}
@@ -533,7 +540,7 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
533
540
reposList = append (reposList , notification .Repository )
534
541
}
535
542
}
536
- return reposList , nil
543
+ return reposList , failed , nil
537
544
}
538
545
539
546
func (nl NotificationList ) getPendingIssueIDs () []int64 {
@@ -550,9 +557,9 @@ func (nl NotificationList) getPendingIssueIDs() []int64 {
550
557
}
551
558
552
559
// LoadIssues loads issues from database
553
- func (nl NotificationList ) LoadIssues () error {
560
+ func (nl NotificationList ) LoadIssues () ([] int , error ) {
554
561
if len (nl ) == 0 {
555
- return nil
562
+ return [] int {}, nil
556
563
}
557
564
558
565
var issueIDs = nl .getPendingIssueIDs ()
@@ -567,15 +574,15 @@ func (nl NotificationList) LoadIssues() error {
567
574
In ("id" , issueIDs [:limit ]).
568
575
Rows (new (Issue ))
569
576
if err != nil {
570
- return err
577
+ return nil , err
571
578
}
572
579
573
580
for rows .Next () {
574
581
var issue Issue
575
582
err = rows .Scan (& issue )
576
583
if err != nil {
577
584
rows .Close ()
578
- return err
585
+ return nil , err
579
586
}
580
587
581
588
issues [issue .ID ] = & issue
@@ -586,13 +593,38 @@ func (nl NotificationList) LoadIssues() error {
586
593
issueIDs = issueIDs [limit :]
587
594
}
588
595
589
- for _ , notification := range nl {
596
+ failures := []int {}
597
+
598
+ for i , notification := range nl {
590
599
if notification .Issue == nil {
591
600
notification .Issue = issues [notification .IssueID ]
601
+ if notification .Issue == nil {
602
+ log .Error ("Notification[%d]: IssueID: %d Not Found" , notification .ID , notification .IssueID )
603
+ failures = append (failures , i )
604
+ continue
605
+ }
592
606
notification .Issue .Repo = notification .Repository
593
607
}
594
608
}
595
- return nil
609
+ return failures , nil
610
+ }
611
+
612
+ // Without returns the notification list without the failures
613
+ func (nl NotificationList ) Without (failures []int ) NotificationList {
614
+ if failures == nil || len (failures ) == 0 {
615
+ return nl
616
+ }
617
+ remaining := make ([]* Notification , 0 , len (nl ))
618
+ last := - 1
619
+ var i int
620
+ for _ , i = range failures {
621
+ remaining = append (remaining , nl [last + 1 :i ]... )
622
+ last = i
623
+ }
624
+ if len (nl ) > i {
625
+ remaining = append (remaining , nl [i + 1 :]... )
626
+ }
627
+ return remaining
596
628
}
597
629
598
630
func (nl NotificationList ) getPendingCommentIDs () []int64 {
@@ -609,9 +641,9 @@ func (nl NotificationList) getPendingCommentIDs() []int64 {
609
641
}
610
642
611
643
// LoadComments loads comments from database
612
- func (nl NotificationList ) LoadComments () error {
644
+ func (nl NotificationList ) LoadComments () ([] int , error ) {
613
645
if len (nl ) == 0 {
614
- return nil
646
+ return [] int {}, nil
615
647
}
616
648
617
649
var commentIDs = nl .getPendingCommentIDs ()
@@ -626,15 +658,15 @@ func (nl NotificationList) LoadComments() error {
626
658
In ("id" , commentIDs [:limit ]).
627
659
Rows (new (Comment ))
628
660
if err != nil {
629
- return err
661
+ return nil , err
630
662
}
631
663
632
664
for rows .Next () {
633
665
var comment Comment
634
666
err = rows .Scan (& comment )
635
667
if err != nil {
636
668
rows .Close ()
637
- return err
669
+ return nil , err
638
670
}
639
671
640
672
comments [comment .ID ] = & comment
@@ -645,13 +677,19 @@ func (nl NotificationList) LoadComments() error {
645
677
commentIDs = commentIDs [limit :]
646
678
}
647
679
648
- for _ , notification := range nl {
680
+ failures := []int {}
681
+ for i , notification := range nl {
649
682
if notification .CommentID > 0 && notification .Comment == nil && comments [notification .CommentID ] != nil {
650
683
notification .Comment = comments [notification .CommentID ]
684
+ if notification .Comment == nil {
685
+ log .Error ("Notification[%d]: CommentID[%d] failed to load" , notification .ID , notification .CommentID )
686
+ failures = append (failures , i )
687
+ continue
688
+ }
651
689
notification .Comment .Issue = notification .Issue
652
690
}
653
691
}
654
- return nil
692
+ return failures , nil
655
693
}
656
694
657
695
// GetNotificationCount returns the notification count for user
0 commit comments