Update chapters in reader only when data will change

In case the chapters already match the "patch" input, an update is not required.
This commit is contained in:
schroda
2024-12-16 14:34:57 +01:00
parent d844ad3f5d
commit fcd44abccd

View File

@@ -40,6 +40,7 @@ import { DirectionOffset } from '@/Base.types.ts';
import {
getChapterIdsForDownloadAhead,
getChapterIdsToDeleteForChapterUpdate,
getReaderChapterFromCache,
} from '@/modules/reader/utils/Reader.utils.ts';
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
import { Queue } from '@/lib/Queue.ts';
@@ -132,6 +133,23 @@ export class ReaderService {
const chapterIdsToUpdate = Chapters.getIds(
shouldSkipDupChapters ? Chapters.addDuplicates([currentChapter], mangaChapters) : [currentChapter],
);
const isUpdateRequired = chapterIdsToUpdate.some((id) => {
const chapterUpToDateData = getReaderChapterFromCache(id);
if (!chapterUpToDateData) {
return false;
}
return (
(patch.isRead !== undefined && patch.isRead !== chapterUpToDateData.isRead) ||
(patch.lastPageRead !== undefined && patch.lastPageRead !== chapterUpToDateData.lastPageRead) ||
(patch.isBookmarked !== undefined && patch.isBookmarked !== chapterUpToDateData.isBookmarked)
);
});
if (!isUpdateRequired) {
return;
}
const chapterIdsToDelete = getChapterIdsToDeleteForChapterUpdate(
currentChapter,
mangaChapters,