Skip to content

Commit 69c8dfe

Browse files
committed
fixes
1 parent 05d9450 commit 69c8dfe

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- Instead of recursively applying patches, now it will apply them one by one
13-
in chain to reduce memory usage [extension#5].
13+
in chain to reduce memory usage [AdguardBrowserExtension#3230].
1414

1515
[1.1.1]: https://github.com/AdguardTeam/DiffBuilder/compare/v1.1.0...v1.1.1
16-
[extension#5]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3230
16+
[AdguardBrowserExtension#3230]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3230
1717

1818
## [1.1.0] - 2025-03-13
1919

src/diff-updater/update.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
363365
export 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

Comments
 (0)