@@ -507,22 +507,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
507
507
508
508
// Filter repos and count issues in them. Count will be used later.
509
509
// USING NON-FINAL STATE OF opts FOR A QUERY.
510
- var issueCountByRepo map [int64 ]int64
511
- {
512
- issueIDs , err := issueIDsFromSearch (ctx , keyword , opts )
513
- if err != nil {
514
- ctx .ServerError ("issueIDsFromSearch" , err )
515
- return
516
- }
517
- if len (issueIDs ) > 0 { // else, no issues found, just leave issueCountByRepo empty
518
- opts .IssueIDs = issueIDs
519
- issueCountByRepo , err = issues_model .CountIssuesByRepo (ctx , opts )
520
- if err != nil {
521
- ctx .ServerError ("CountIssuesByRepo" , err )
522
- return
523
- }
524
- opts .IssueIDs = nil // reset, the opts will be used later
525
- }
510
+ issueCountByRepo , err := issue_indexer .CountIssuesByRepo (ctx , issue_indexer .ToSearchOptions (keyword , opts ))
511
+ if err != nil {
512
+ ctx .ServerError ("CountIssuesByRepo" , err )
513
+ return
526
514
}
527
515
528
516
// Make sure page number is at least 1. Will be posted to ctx.Data.
@@ -615,44 +603,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
615
603
// -------------------------------
616
604
// Fill stats to post to ctx.Data.
617
605
// -------------------------------
618
- var issueStats * issues_model.IssueStats
619
- {
620
- statsOpts := issues_model.IssuesOptions {
621
- RepoIDs : repoIDs ,
622
- User : ctx .Doer ,
623
- IsPull : util .OptionalBoolOf (isPullList ),
624
- IsClosed : util .OptionalBoolOf (isShowClosed ),
625
- IssueIDs : nil ,
626
- IsArchived : util .OptionalBoolFalse ,
627
- LabelIDs : opts .LabelIDs ,
628
- Org : org ,
629
- Team : team ,
630
- RepoCond : opts .RepoCond ,
631
- }
632
-
633
- if keyword != "" {
634
- statsOpts .RepoIDs = opts .RepoIDs
635
- allIssueIDs , err := issueIDsFromSearch (ctx , keyword , & statsOpts )
636
- if err != nil {
637
- ctx .ServerError ("issueIDsFromSearch" , err )
638
- return
639
- }
640
- statsOpts .IssueIDs = allIssueIDs
641
- }
642
-
643
- if keyword != "" && len (statsOpts .IssueIDs ) == 0 {
644
- // So it did search with the keyword, but no issue found.
645
- // Just set issueStats to empty.
646
- issueStats = & issues_model.IssueStats {}
647
- } else {
648
- // So it did search with the keyword, and found some issues. It needs to get issueStats of these issues.
649
- // Or the keyword is empty, so it doesn't need issueIDs as filter, just get issueStats with statsOpts.
650
- issueStats , err = issues_model .GetUserIssueStats (filterMode , statsOpts )
651
- if err != nil {
652
- ctx .ServerError ("GetUserIssueStats" , err )
653
- return
654
- }
655
- }
606
+ issueStats , err := getUserIssueStats (ctx , issue_indexer .ToSearchOptions (keyword , opts ), ctx .Doer .ID )
607
+ if err != nil {
608
+ ctx .ServerError ("getUserIssueStats" , err )
609
+ return
656
610
}
657
611
658
612
// Will be posted to ctx.Data.
@@ -777,6 +731,7 @@ func getRepoIDs(reposQuery string) []int64 {
777
731
return repoIDs
778
732
}
779
733
734
+ // TBC: remove it
780
735
func issueIDsFromSearch (ctx * context.Context , keyword string , opts * issues_model.IssuesOptions ) ([]int64 , error ) {
781
736
ids , _ , err := issue_indexer .SearchIssues (ctx , issue_indexer .ToSearchOptions (keyword , opts ))
782
737
if err != nil {
@@ -913,3 +868,95 @@ func UsernameSubRoute(ctx *context.Context) {
913
868
}
914
869
}
915
870
}
871
+
872
+ func getUserIssueStats (ctx * context.Context , opts * issue_indexer.SearchOptions , doerID int64 ) (* issues_model.IssueStats , error ) {
873
+ isClosed := opts .IsClosed
874
+ assigneeID := opts .AssigneeID
875
+ posterID := opts .PosterID
876
+ mentionID := opts .MentionID
877
+ reviewRequestedID := opts .ReviewRequestedID
878
+ reviewedID := opts .ReviewedID
879
+ defer func () {
880
+ opts .IsClosed = isClosed
881
+ opts .AssigneeID = assigneeID
882
+ opts .PosterID = posterID
883
+ opts .MentionID = mentionID
884
+ opts .ReviewRequestedID = reviewRequestedID
885
+ opts .ReviewedID = reviewedID
886
+ }()
887
+ opts .IsClosed = util .OptionalBoolNone
888
+ opts .AssigneeID = nil
889
+ opts .PosterID = nil
890
+ opts .MentionID = nil
891
+ opts .ReviewRequestedID = nil
892
+ opts .ReviewedID = nil
893
+
894
+ var (
895
+ err error
896
+ ret = & issues_model.IssueStats {}
897
+ )
898
+
899
+ {
900
+ opts .IsClosed = util .OptionalBoolFalse
901
+ ret .OpenCount , err = issue_indexer .CountIssues (ctx , opts )
902
+ if err != nil {
903
+ return nil , err
904
+ }
905
+ opts .IsClosed = util .OptionalBoolNone
906
+ }
907
+ {
908
+ opts .IsClosed = util .OptionalBoolTrue
909
+ ret .ClosedCount , err = issue_indexer .CountIssues (ctx , opts )
910
+ if err != nil {
911
+ return nil , err
912
+ }
913
+ opts .IsClosed = util .OptionalBoolNone
914
+ }
915
+ {
916
+ ret .YourRepositoriesCount , err = issue_indexer .CountIssues (ctx , opts )
917
+ if err != nil {
918
+ return nil , err
919
+ }
920
+ }
921
+ {
922
+ opts .AssigneeID = & doerID
923
+ ret .AssignCount , err = issue_indexer .CountIssues (ctx , opts )
924
+ if err != nil {
925
+ return nil , err
926
+ }
927
+ opts .AssigneeID = nil
928
+ }
929
+ {
930
+ opts .PosterID = & doerID
931
+ ret .CreateCount , err = issue_indexer .CountIssues (ctx , opts )
932
+ if err != nil {
933
+ return nil , err
934
+ }
935
+ opts .PosterID = nil
936
+ }
937
+ {
938
+ opts .MentionID = & doerID
939
+ ret .MentionCount , err = issue_indexer .CountIssues (ctx , opts )
940
+ if err != nil {
941
+ return nil , err
942
+ }
943
+ opts .MentionID = nil
944
+ }
945
+ {
946
+ opts .ReviewRequestedID = & doerID
947
+ ret .ReviewRequestedCount , err = issue_indexer .CountIssues (ctx , opts )
948
+ if err != nil {
949
+ return nil , err
950
+ }
951
+ opts .ReviewRequestedID = nil
952
+ }
953
+ {
954
+ opts .ReviewedID = & doerID
955
+ ret .ReviewedCount , err = issue_indexer .CountIssues (ctx , opts )
956
+ if err != nil {
957
+ return nil , err
958
+ }
959
+ opts .ReviewedID = nil
960
+ }
961
+ return ret , nil
962
+ }
0 commit comments