@@ -290,7 +290,8 @@ const downloadFile = async (
290290 }
291291
292292 if ( ( response . status === AcceptableHttpStatusCodes . NotFound
293- || response . status === AcceptableHttpStatusCodes . NoContent ) ) {
293+ || response . status === AcceptableHttpStatusCodes . NoContent )
294+ ) {
294295 if ( ! isRecursiveUpdate ) {
295296 log ( 'Update is not available.' ) ;
296297 }
@@ -352,12 +353,13 @@ export const extractBaseUrl = (filterUrl: string): string => {
352353 * @param params The parameters for applying the patch {@link ApplyPatchParams}.
353354 *
354355 * @returns A promise that resolves to the updated filter content after applying the patch,
355- * or null if there is no Diff-Path tag in the filter.
356+ * or null only if there is no Diff-Path tag in the filter - this is a special
357+ * case to prevent future unnecessary patch requests.
356358 *
357359 * @throws
358360 * 1. An {@link Error} if there is an error during
359361 * - the patch application process
360- * - during network request.
362+ * - or during the network request.
361363 * 2. The {@link UnacceptableResponseError} if the network request returns an unacceptable status code.
362364 */
363365export const applyPatch = async ( params : ApplyPatchParams ) : Promise < string | null > => {
@@ -446,31 +448,30 @@ export const applyPatch = async (params: ApplyPatchParams): Promise<string | nul
446448
447449 const paramsWithRecursiveFlag = { ...params , isRecursiveUpdate : false } ;
448450
449- let task : Promise < AppliedPatchResult | null > | null = applyPatchWrapper ( paramsWithRecursiveFlag ) ;
451+ let applyingPatchTask : Promise < AppliedPatchResult | null > | null = applyPatchWrapper ( paramsWithRecursiveFlag ) ;
450452 let latestFilter : string | null = null ;
451453
452- // Apply patches until there are no more tasks to process .
454+ // Apply patches until there are no more new patches to apply .
453455 // This allows to apply multiple patches in a row if the filter supports it
454456 // without recursive calls, since applying patches can be a memory-intensive
455457 // operation, because of large amount of contexts for each function call.
456- while ( task ) {
458+ while ( applyingPatchTask ) {
457459 let freshFilter : AppliedPatchResult | null = null ;
458460
459461 // Without try-await since we should throw an error in some cases and
460462 // all needed catches are inside the `applyPatchWrapper` function.
461463 // eslint-disable-next-line no-await-in-loop
462- freshFilter = await task ;
464+ freshFilter = await applyingPatchTask ;
463465
464466 // If there is no fresh filter, it means that the patch was not applied
465- // or the filter does not support Diff-Path tag anymore.
467+ // or the filter does not support Diff-Path tag anymore, so we return
468+ // the latest filter content.
466469 if ( ! freshFilter ) {
467- // If there is no result, it means that the patch was not applied
468- // or the filter does not support Diff-Path tag anymore.
469470 return latestFilter ;
470471 }
471472
472473 latestFilter = freshFilter . filterContent ;
473- task = freshFilter . nextPatchTask || null ;
474+ applyingPatchTask = freshFilter . nextPatchTask || null ;
474475 }
475476
476477 return latestFilter ;
0 commit comments