88using GitHub . Models ;
99using GitHub . Primitives ;
1010using Octokit . GraphQL ;
11+ using Octokit . GraphQL . Model ;
1112using static Octokit . GraphQL . Variable ;
1213
1314namespace GitHub . Services
@@ -18,7 +19,7 @@ public class IssuesAutoCompleteSource : IAutoCompleteSource
1819 {
1920 readonly ITeamExplorerContext teamExplorerContext ;
2021 readonly IGraphQLClientFactory graphqlFactory ;
21- ICompiledQuery < List < SuggestionItem > > query ;
22+ ICompiledQuery < Page < SuggestionItem > > query ;
2223
2324 [ ImportingConstructor ]
2425 public IssuesAutoCompleteSource ( ITeamExplorerContext teamExplorerContext , IGraphQLClientFactory graphqlFactory )
@@ -38,32 +39,58 @@ public IObservable<AutoCompleteSuggestion> GetSuggestions()
3839 var owner = localRepositoryModel . Owner ;
3940 var name = localRepositoryModel . Name ;
4041
42+ string filter ;
43+ string after ;
44+
4145 if ( query == null )
4246 {
43- query = new Query ( ) . Repository ( owner : Var ( nameof ( owner ) ) , name : Var ( nameof ( name ) ) )
44- . Select ( repository =>
45- repository . Issues ( null , null , null , null , null , null , null )
46- . AllPages ( )
47- . Select ( issue => new SuggestionItem ( "#" + issue . Number , issue . Title )
48- {
49- LastModifiedDate = issue . LastEditedAt
50- } )
51- . ToList ( ) )
52- . Compile ( ) ;
47+ query = new Query ( ) . Search ( query : Var ( nameof ( filter ) ) , SearchType . Issue , 100 , after : Var ( nameof ( after ) ) )
48+ . Select ( item => new Page < SuggestionItem >
49+ {
50+ Items = item . Nodes . Select ( searchResultItem =>
51+ searchResultItem . Switch < SuggestionItem > ( selector => selector
52+ . Issue ( i => new SuggestionItem ( "#" + i . Number , i . Title ) { LastModifiedDate = i . LastEditedAt } )
53+ . PullRequest ( p => new SuggestionItem ( "#" + p . Number , p . Title ) { LastModifiedDate = p . LastEditedAt } ) )
54+ ) . ToList ( ) ,
55+ EndCursor = item . PageInfo . EndCursor ,
56+ HasNextPage = item . PageInfo . HasNextPage ,
57+ TotalCount = item . IssueCount
58+ } )
59+ . Compile ( ) ;
5360 }
5461
55- var variables = new Dictionary < string , object >
56- {
57- { nameof ( owner ) , owner } ,
58- { nameof ( name ) , name } ,
59- } ;
62+ filter = $ "repo:{ owner } /{ name } is:open";
6063
6164 return Observable . FromAsync ( async ( ) =>
65+ {
66+ var results = new List < SuggestionItem > ( ) ;
67+
68+ var variables = new Dictionary < string , object >
69+ {
70+ { nameof ( filter ) , filter } ,
71+ } ;
72+
73+ var connection = await graphqlFactory . CreateConnection ( hostAddress ) ;
74+ var searchResults = await connection . Run ( query , variables ) ;
75+
76+ results . AddRange ( searchResults . Items ) ;
77+
78+ while ( searchResults . HasNextPage )
6279 {
63- var connection = await graphqlFactory . CreateConnection ( hostAddress ) ;
64- var suggestions = await connection . Run ( query , variables ) ;
65- return suggestions . Select ( suggestion => new IssueAutoCompleteSuggestion ( suggestion , Prefix ) ) ;
66- } ) . SelectMany ( enumerable => enumerable ) ;
80+ variables [ nameof ( after ) ] = searchResults . EndCursor ;
81+ searchResults = await connection . Run ( query , variables ) ;
82+
83+ results . AddRange ( searchResults . Items ) ;
84+ }
85+
86+ return results . Select ( item => new IssueAutoCompleteSuggestion ( item , Prefix ) ) ;
87+
88+ } ) . SelectMany ( observable => observable ) ;
89+ }
90+
91+ class SearchResult
92+ {
93+ public SuggestionItem SuggestionItem { get ; set ; }
6794 }
6895
6996 public string Prefix
0 commit comments