diff --git a/CHANGELOG.md b/CHANGELOG.md index d178937a..8ef5ab1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - (**Migration**) Sort destination source selection by same order as browse source page - (**Migration**) Sort entries in search/execution page by title - (**Migration**) Prevent a manual selected match from getting automatically overwritten by a new-found match +- (**Migration**) Abort active search when selecting a match through the manual search ### Fixed diff --git a/src/features/migration/MigrationManager.ts b/src/features/migration/MigrationManager.ts index e2c2172c..da5ed7d6 100644 --- a/src/features/migration/MigrationManager.ts +++ b/src/features/migration/MigrationManager.ts @@ -97,7 +97,8 @@ export class MigrationManager { private static mangaProcessQueue = pLimit(MAX_MANGAS_IN_PARALLEL); private static parallelSourcesQueue: LimitFunction | undefined; - private static queueBySource = new Map(); + private static queueBySource = new Map(); + private static searchAbortControllerByManga = new Map(); private static abortAndResetAbortController(reason: unknown): void { MigrationManager.abortController?.abort(reason); @@ -617,7 +618,16 @@ export class MigrationManager { draft.entries[mangaId].manualMatches = [...draft.entries[mangaId].manualMatches, match]; } + const isSearching = ![ + MigrationEntryStatus.SEARCH_FAILED, + MigrationEntryStatus.SEARCH_COMPLETE, + ].includes(entry.status); + MigrationManager.selectMatch(mangaId, match.id, match.sourceId, true); + + if (isSearching) { + MigrationManager.searchAbortControllerByManga.get(mangaId)?.abort('Manual match selected'); + } } }); } @@ -705,10 +715,6 @@ export class MigrationManager { throw new Error(signal.reason); } - if (signal.aborted) { - throw new Error(signal.reason); - } - if (!selectHighestChapterNumberSource && MigrationManager.hasHigherSourcePriorityMatch(mangaId, sourceId)) { throw new Error('Entry already has a selected match from a higher priority source'); } @@ -803,6 +809,9 @@ export class MigrationManager { const searchController = new AbortController(); const signal = AbortSignal.any([mainSignal, searchController.signal]); + MigrationManager.searchAbortControllerByManga.get(mangaId)?.abort('search'); + MigrationManager.searchAbortControllerByManga.set(mangaId, searchController); + if (!entry) { return; } @@ -973,6 +982,8 @@ export class MigrationManager { draft.searchProgress.completed += 1; draft.searchProgress.failed += 1; }); + } finally { + MigrationManager.searchAbortControllerByManga.delete(mangaId); } }