From fcd44abccd23ff12fe4203c466d2c2f55e26f93c Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:34:57 +0100 Subject: [PATCH] Update chapters in reader only when data will change In case the chapters already match the "patch" input, an update is not required. --- src/modules/reader/services/ReaderService.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/modules/reader/services/ReaderService.ts b/src/modules/reader/services/ReaderService.ts index 920227c4..d4eb92bc 100644 --- a/src/modules/reader/services/ReaderService.ts +++ b/src/modules/reader/services/ReaderService.ts @@ -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,