@@ -559,6 +559,74 @@ func (issues IssueList) LoadDiscussComments(ctx context.Context) error {
559
559
return issues .loadComments (ctx , builder.Eq {"comment.type" : CommentTypeComment })
560
560
}
561
561
562
+ // GetBlockedByCounts returns a map of issue ID to number of open issues that are blocking it
563
+ func (issues IssueList ) GetBlockedByCount (ctx context.Context ) (map [int64 ]int64 , error ) {
564
+ type BlockedByCount struct {
565
+ IssueID int64
566
+ Count int64
567
+ }
568
+
569
+ bCounts := make ([]* BlockedByCount , len (issues ))
570
+ ids := make ([]int64 , len (issues ))
571
+ for i , issue := range issues {
572
+ ids [i ] = issue .ID
573
+ }
574
+
575
+ sess := db .GetEngine (ctx ).In ("issue_id" , ids )
576
+ err := sess .Select ("issue_id, count(issue_dependency.id) as `count`" ).
577
+ Join ("INNER" , "issue" , "issue.id = issue_dependency.dependency_id" ).
578
+ Where ("is_closed = ?" , false ).
579
+ GroupBy ("issue_id" ).
580
+ OrderBy ("issue_id" ).
581
+ Table ("issue_dependency" ).
582
+ Find (& bCounts )
583
+ if err != nil {
584
+ return nil , err
585
+ }
586
+
587
+ blockedByCountMap := make (map [int64 ]int64 , len (issues ))
588
+ for _ , c := range bCounts {
589
+ if c != nil {
590
+ blockedByCountMap [c .IssueID ] = c .Count
591
+ }
592
+ }
593
+
594
+ return blockedByCountMap , nil
595
+ }
596
+
597
+ // GetBlockingCounts returns a map of issue ID to number of issues that are blocked by it
598
+ func (issues IssueList ) GetBlockingCount (ctx context.Context ) (map [int64 ]int64 , error ) {
599
+ type BlockingCount struct {
600
+ IssueID int64
601
+ Count int64
602
+ }
603
+
604
+ bCounts := make ([]* BlockingCount , 0 , len (issues ))
605
+ ids := make ([]int64 , len (issues ))
606
+ for i , issue := range issues {
607
+ ids [i ] = issue .ID
608
+ }
609
+
610
+ sess := db .GetEngine (ctx ).In ("dependency_id" , ids )
611
+ err := sess .Select ("dependency_id as `issue_id`, count(id) as `count`" ).
612
+ GroupBy ("dependency_id" ).
613
+ OrderBy ("dependency_id" ).
614
+ Table ("issue_dependency" ).
615
+ Find (& bCounts )
616
+ if err != nil {
617
+ return nil , err
618
+ }
619
+
620
+ blockingCountMap := make (map [int64 ]int64 , len (issues ))
621
+ for _ , c := range bCounts {
622
+ if c != nil {
623
+ blockingCountMap [c .IssueID ] = c .Count
624
+ }
625
+ }
626
+
627
+ return blockingCountMap , nil
628
+ }
629
+
562
630
// GetApprovalCounts returns a map of issue ID to slice of approval counts
563
631
// FIXME: only returns official counts due to double counting of non-official approvals
564
632
func (issues IssueList ) GetApprovalCounts (ctx context.Context ) (map [int64 ][]* ReviewCount , error ) {
0 commit comments