@@ -1058,6 +1058,34 @@ async function executeLightCombinedQuery(
10581058 }
10591059}
10601060
1061+ /** Cap-check, notify, and assemble a LightSearchResult from working collections. */
1062+ function finalizeSearchResult (
1063+ issues : Issue [ ] ,
1064+ prMap : Map < number , PullRequest > ,
1065+ nodeIdMap : Map < number , string > ,
1066+ errors : ApiError [ ] ,
1067+ issueSource : string ,
1068+ prSource : string ,
1069+ issueLabel : string ,
1070+ prLabel : string ,
1071+ ) : LightSearchResult {
1072+ if ( issues . length >= SEARCH_RESULT_CAP ) {
1073+ console . warn ( `[api] ${ issueLabel } capped at ${ SEARCH_RESULT_CAP } ` ) ;
1074+ pushNotification ( issueSource , `${ issueLabel } capped at ${ SEARCH_RESULT_CAP . toLocaleString ( "en-US" ) } — some items are hidden` , "warning" ) ;
1075+ issues . splice ( SEARCH_RESULT_CAP ) ;
1076+ }
1077+
1078+ if ( prMap . size >= SEARCH_RESULT_CAP ) {
1079+ console . warn ( `[api] ${ prLabel } capped at ${ SEARCH_RESULT_CAP } ` ) ;
1080+ pushNotification ( prSource , `${ prLabel } capped at ${ SEARCH_RESULT_CAP . toLocaleString ( "en-US" ) } — some items are hidden` , "warning" ) ;
1081+ }
1082+
1083+ const pullRequests = [ ...prMap . values ( ) ] ;
1084+ if ( pullRequests . length >= SEARCH_RESULT_CAP ) pullRequests . splice ( SEARCH_RESULT_CAP ) ;
1085+ const prNodeIds = pullRequests . map ( ( pr ) => nodeIdMap . get ( pr . id ) ) . filter ( ( id ) : id is string => id != null ) ;
1086+ return { issues, pullRequests, prNodeIds, errors } ;
1087+ }
1088+
10611089/**
10621090 * Phase 1: light combined search. Fetches issues fully and PRs with minimal fields.
10631091 * Returns light PRs (enriched: false) and their GraphQL node IDs for phase 2 backfill.
@@ -1101,22 +1129,11 @@ async function graphqlLightCombinedSearch(
11011129 }
11021130 } ) ) ;
11031131
1104- if ( issues . length >= SEARCH_RESULT_CAP ) {
1105- console . warn ( `[api] Issue search results capped at ${ SEARCH_RESULT_CAP } ` ) ;
1106- pushNotification ( "search/issues" , `Issue search results capped at ${ SEARCH_RESULT_CAP . toLocaleString ( "en-US" ) } — some items are hidden` , "warning" ) ;
1107- issues . splice ( SEARCH_RESULT_CAP ) ;
1108- }
1109-
1110- if ( prMap . size >= SEARCH_RESULT_CAP ) {
1111- console . warn ( `[api] PR search results capped at ${ SEARCH_RESULT_CAP } ` ) ;
1112- pushNotification ( "search/prs" , `PR search results capped at ${ SEARCH_RESULT_CAP . toLocaleString ( "en-US" ) } — some items are hidden` , "warning" ) ;
1113- }
1114-
1115- const pullRequests = [ ...prMap . values ( ) ] ;
1116- if ( pullRequests . length >= SEARCH_RESULT_CAP ) pullRequests . splice ( SEARCH_RESULT_CAP ) ;
1117- const prNodeIds = pullRequests . map ( ( pr ) => nodeIdMap . get ( pr . id ) ) . filter ( ( id ) : id is string => id != null ) ;
1118-
1119- return { issues, pullRequests, prNodeIds, errors } ;
1132+ return finalizeSearchResult (
1133+ issues , prMap , nodeIdMap , errors ,
1134+ "search/issues" , "search/prs" ,
1135+ "Issue search results" , "PR search results" ,
1136+ ) ;
11201137}
11211138
11221139/**
@@ -1207,21 +1224,11 @@ async function graphqlUnfilteredSearch(
12071224 }
12081225 } ) ) ;
12091226
1210- if ( issues . length >= SEARCH_RESULT_CAP ) {
1211- console . warn ( `[api] Unfiltered issue results capped at ${ SEARCH_RESULT_CAP } ` ) ;
1212- pushNotification ( "search/unfiltered-issues" , `Monitored repo issue results capped at ${ SEARCH_RESULT_CAP . toLocaleString ( "en-US" ) } — some items are hidden` , "warning" ) ;
1213- issues . splice ( SEARCH_RESULT_CAP ) ;
1214- }
1215-
1216- if ( prMap . size >= SEARCH_RESULT_CAP ) {
1217- console . warn ( `[api] Unfiltered PR results capped at ${ SEARCH_RESULT_CAP } ` ) ;
1218- pushNotification ( "search/unfiltered-prs" , `Monitored repo PR results capped at ${ SEARCH_RESULT_CAP . toLocaleString ( "en-US" ) } — some items are hidden` , "warning" ) ;
1219- }
1220-
1221- const pullRequests = [ ...prMap . values ( ) ] ;
1222- if ( pullRequests . length >= SEARCH_RESULT_CAP ) pullRequests . splice ( SEARCH_RESULT_CAP ) ;
1223- const prNodeIds = pullRequests . map ( ( pr ) => nodeIdMap . get ( pr . id ) ) . filter ( ( id ) : id is string => id != null ) ;
1224- return { issues, pullRequests, prNodeIds, errors } ;
1227+ return finalizeSearchResult (
1228+ issues , prMap , nodeIdMap , errors ,
1229+ "search/unfiltered-issues" , "search/unfiltered-prs" ,
1230+ "Monitored repo issue results" , "Monitored repo PR results" ,
1231+ ) ;
12251232}
12261233
12271234// ── Two-phase: heavy backfill ─────────────────────────────────────────────────
@@ -2210,7 +2217,7 @@ export async function validateGitHubUser(
22102217 login : raw . login . toLowerCase ( ) ,
22112218 avatarUrl,
22122219 name : raw . name ?? null ,
2213- type : raw . type === "Bot" ? "bot" as const : "user" as const ,
2220+ type : raw . type === "Bot" ? "bot" : "user" ,
22142221 } ;
22152222}
22162223
0 commit comments