@@ -29,7 +29,6 @@ import {
2929 aliasedPullRequests ,
3030 githubCheckCounts ,
3131 githubMergeable ,
32- loadInHalves ,
3332 pullRequestChunks ,
3433 pullRequestHeadFactsNodeSchema ,
3534 type PullRequestRef ,
@@ -154,12 +153,13 @@ async function expirePending(cache: PluginCache, key: string): Promise<void> {
154153
155154/**
156155 * Run the due patches: one query reads the merge state and checks of up
157- * to 25 pull requests, and a failed query splits in halves. A patch whose
158- * merge state GitHub still computes, whose read is older than its entry,
159- * or whose query fails alone, waits for the next heartbeat. A patch with
160- * no pull request in the answer, or out of attempts, is dropped, and its
161- * entry is read again soon. A failed query is logged, not thrown, so the
162- * rest of the heartbeat still runs.
156+ * to 25 pull requests. A patch whose merge state GitHub still computes,
157+ * whose read is older than its entry, or whose query fails, waits for the
158+ * next heartbeat. A failed query does not split, so an outage costs one
159+ * query per chunk. A patch with no pull request in the answer, or out of
160+ * attempts, is dropped, and its entry is read again
161+ * soon. A failed query is logged, not thrown, so the rest of the heartbeat
162+ * still runs.
163163 */
164164export async function runGitHubPullRequestPatches ( args : {
165165 cache : PluginCache ;
@@ -184,49 +184,41 @@ export async function runGitHubPullRequestPatches(args: {
184184 if ( ! ref ) dropped . push ( key ) ;
185185 return ref ? [ { due : [ key , patch ] satisfies Due , ref } ] : [ ] ;
186186 } ) ;
187- // The queries of every chunk and of its halves share one limit.
188- const queries = pLimit ( PATCH_QUERY_CONCURRENCY ) ;
189187 await pLimit ( PATCH_QUERY_CONCURRENCY ) . map (
190188 pullRequestChunks ( reads ) ,
191- async ( chunk ) =>
192- await loadInHalves ( {
193- failed : async ( [ read ] , error ) => {
194- if ( ! read ) return ;
195- again . push ( read . due ) ;
196- args . log . error (
197- "GitHub pull request patch query failed" ,
198- {
199- number : read . ref . number ,
200- repository : `${ read . ref . owner } /${ read . ref . name } ` ,
201- } ,
202- error ,
203- ) ;
204- } ,
205- items : chunk ,
206- load : async ( part ) => {
207- // Answer `p<i>` is the pull request of `part[i]`.
208- const nodes = aliasedPullRequests (
209- await queries ( ( ) =>
210- args . loadHeadFacts ( part . map ( ( read ) => read . ref ) ) ,
211- ) ,
212- part . length ,
213- pullRequestHeadFactsNodeSchema ,
214- ) ;
215- for ( const [ index , { due : entry } ] of part . entries ( ) ) {
216- const [ key , patch ] = entry ;
217- const node = nodes [ index ] ;
218- if ( ! node ) {
219- dropped . push ( key ) ;
220- continue ;
221- }
222- const last = patch . attempts + 1 >= PATCH_MAX_ATTEMPTS ;
223- // oxlint-disable-next-line no-await-in-loop -- Each write takes its own entry lock; patches are few.
224- if ( await writeHeadFacts ( args . cache , key , node , last ) ) {
225- again . push ( entry ) ;
226- }
227- }
228- } ,
229- } ) ,
189+ async ( chunk ) => {
190+ let response : unknown ;
191+ try {
192+ response = await args . loadHeadFacts ( chunk . map ( ( read ) => read . ref ) ) ;
193+ } catch ( error ) {
194+ again . push ( ...chunk . map ( ( read ) => read . due ) ) ;
195+ args . log . error (
196+ "GitHub pull request patch query failed" ,
197+ { pullRequests : chunk . length } ,
198+ error ,
199+ ) ;
200+ return ;
201+ }
202+ // Answer `p<i>` is the pull request of `chunk[i]`.
203+ const nodes = aliasedPullRequests (
204+ response ,
205+ chunk . length ,
206+ pullRequestHeadFactsNodeSchema ,
207+ ) ;
208+ for ( const [ index , { due : entry } ] of chunk . entries ( ) ) {
209+ const [ key , patch ] = entry ;
210+ const node = nodes [ index ] ;
211+ if ( ! node ) {
212+ dropped . push ( key ) ;
213+ continue ;
214+ }
215+ const last = patch . attempts + 1 >= PATCH_MAX_ATTEMPTS ;
216+ // oxlint-disable-next-line no-await-in-loop -- Each write takes its own entry lock; patches are few.
217+ if ( await writeHeadFacts ( args . cache , key , node , last ) ) {
218+ again . push ( entry ) ;
219+ }
220+ }
221+ } ,
230222 ) ;
231223 const retries = again . filter (
232224 ( [ , patch ] ) => patch . attempts + 1 < PATCH_MAX_ATTEMPTS ,
0 commit comments