Fix updating migration search progress on manual match selection
The "success" and "completed" count could become larger than the "total" count when manually selecting a match for a successful search with no automatically selected match (e.g. when all matches are outdated)
This commit is contained in:
@@ -10,6 +10,10 @@ import type { MigratableEntry, TMigrationEntry } from '@/features/migration/Migr
|
|||||||
import { MigrationEntryStatus } from '@/features/migration/Migration.types.ts';
|
import { MigrationEntryStatus } from '@/features/migration/Migration.types.ts';
|
||||||
|
|
||||||
export class MigrationEntries {
|
export class MigrationEntries {
|
||||||
|
public static isSearching(entry: TMigrationEntry): boolean {
|
||||||
|
return [MigrationEntryStatus.PENDING, MigrationEntryStatus.SEARCHING].includes(entry.status);
|
||||||
|
}
|
||||||
|
|
||||||
public static getExcluded(entries: TMigrationEntry[]): TMigrationEntry[] {
|
public static getExcluded(entries: TMigrationEntry[]): TMigrationEntry[] {
|
||||||
return entries.filter((entry) => entry.isExcluded);
|
return entries.filter((entry) => entry.isExcluded);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -589,18 +589,13 @@ export class MigrationManager {
|
|||||||
MigrationManager.updateState((draft) => {
|
MigrationManager.updateState((draft) => {
|
||||||
const entry = draft.entries[mangaId];
|
const entry = draft.entries[mangaId];
|
||||||
if (entry) {
|
if (entry) {
|
||||||
const isSearching = ![
|
if (MigrationEntries.isSearching(entry)) {
|
||||||
MigrationEntryStatus.SEARCH_FAILED,
|
|
||||||
MigrationEntryStatus.SEARCH_COMPLETE,
|
|
||||||
].includes(entry.status);
|
|
||||||
if (isSearching) {
|
|
||||||
draft.searchProgress.completed += 1;
|
draft.searchProgress.completed += 1;
|
||||||
draft.searchProgress.success += 1;
|
draft.searchProgress.success += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.status = MigrationEntryStatus.SEARCH_COMPLETE;
|
entry.status = MigrationEntryStatus.SEARCH_COMPLETE;
|
||||||
entry.isManualSelection = true;
|
entry.isManualSelection = true;
|
||||||
|
|
||||||
entry.selectedMatchMangaId = targetMangaId;
|
entry.selectedMatchMangaId = targetMangaId;
|
||||||
entry.selectedMatchSourceId = targetSourceId;
|
entry.selectedMatchSourceId = targetSourceId;
|
||||||
}
|
}
|
||||||
@@ -623,15 +618,7 @@ export class MigrationManager {
|
|||||||
draft.entries[mangaId].manualMatches = [...draft.entries[mangaId].manualMatches, match];
|
draft.entries[mangaId].manualMatches = [...draft.entries[mangaId].manualMatches, match];
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSearching = ![
|
const isSearching = MigrationEntries.isSearching(entry);
|
||||||
MigrationEntryStatus.SEARCH_FAILED,
|
|
||||||
MigrationEntryStatus.SEARCH_COMPLETE,
|
|
||||||
].includes(entry.status);
|
|
||||||
|
|
||||||
if (isSearching) {
|
|
||||||
draft.searchProgress.completed += 1;
|
|
||||||
draft.searchProgress.success += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.status = MigrationEntryStatus.SEARCH_COMPLETE;
|
entry.status = MigrationEntryStatus.SEARCH_COMPLETE;
|
||||||
entry.isManualSelection = true;
|
entry.isManualSelection = true;
|
||||||
@@ -639,6 +626,8 @@ export class MigrationManager {
|
|||||||
entry.selectedMatchSourceId = match.sourceId;
|
entry.selectedMatchSourceId = match.sourceId;
|
||||||
|
|
||||||
if (isSearching) {
|
if (isSearching) {
|
||||||
|
draft.searchProgress.completed += 1;
|
||||||
|
draft.searchProgress.success += 1;
|
||||||
MigrationManager.searchAbortControllerByManga.get(mangaId)?.abort('Manual match selected');
|
MigrationManager.searchAbortControllerByManga.get(mangaId)?.abort('Manual match selected');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1003,6 +992,10 @@ export class MigrationManager {
|
|||||||
MigrationManager.updateState((draft) => {
|
MigrationManager.updateState((draft) => {
|
||||||
const draftEntry = draft.entries[mangaId];
|
const draftEntry = draft.entries[mangaId];
|
||||||
|
|
||||||
|
if (!MigrationEntries.isSearching(draftEntry)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (draftEntry.searchMatches.length) {
|
if (draftEntry.searchMatches.length) {
|
||||||
if (draftEntry.selectedMatchMangaId != null) {
|
if (draftEntry.selectedMatchMangaId != null) {
|
||||||
draftEntry.status = MigrationEntryStatus.SEARCH_COMPLETE;
|
draftEntry.status = MigrationEntryStatus.SEARCH_COMPLETE;
|
||||||
@@ -1012,9 +1005,6 @@ export class MigrationManager {
|
|||||||
} else {
|
} else {
|
||||||
draftEntry.status = MigrationEntryStatus.NO_MATCH;
|
draftEntry.status = MigrationEntryStatus.NO_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
draft.searchProgress.success += 1;
|
|
||||||
draft.searchProgress.completed += 1;
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (mainSignal.aborted) {
|
if (mainSignal.aborted) {
|
||||||
|
|||||||
Reference in New Issue
Block a user