diff --git a/src/database/queries/ChapterQueries.ts b/src/database/queries/ChapterQueries.ts index c48dbf12..8ed85f7d 100644 --- a/src/database/queries/ChapterQueries.ts +++ b/src/database/queries/ChapterQueries.ts @@ -379,7 +379,7 @@ const deleteDownloadedImages = async ( } } } catch (error) { - showToast(error.message); + showToast((error as Error).message); } }; diff --git a/src/redux/novel/novel.actions.js b/src/redux/novel/novel.actions.js index ca2ae3a6..389b5bdc 100644 --- a/src/redux/novel/novel.actions.js +++ b/src/redux/novel/novel.actions.js @@ -444,16 +444,57 @@ export const deleteChapterAction = */ export const deleteAllChaptersAction = (sourceId, chapters) => async dispatch => { - await Promise.all( - chapters.map(async chapter => { - await deleteChapter(sourceId, chapter.novelId, chapter.chapterId); + await new Promise((res, rej) => { + (async () => { + const downloaded = chapters.filter(f => !!f.downloaded); + if (downloaded.length === 0) { + res(); + } - dispatch({ - type: CHAPTER_DELETED, - payload: chapter.chapterId, - }); - }), - ); + const coccurent = 5; + /** + * @type {Promise[][]} + */ + const removeBatches = []; + for (let i = 0; i < downloaded.length; i++) { + if (i % coccurent === 0) { + removeBatches.push([]); + } + removeBatches[removeBatches.length - 1].push( + new Promise(resolveRemoval => { + (async () => { + const chapter = downloaded[i]; + await deleteChapter( + sourceId, + chapter.novelId, + chapter.chapterId, + ); + + dispatch({ + type: CHAPTER_DELETED, + payload: chapter.chapterId, + }); + resolveRemoval(); + })(); + }), + ); + } + for (const rb of removeBatches) { + await Promise.all(rb); + } + res(); + })(); + }); + // await Promise.all( + // chapters.map(async chapter => { + // await deleteChapter(sourceId, chapter.novelId, chapter.chapterId); + + // dispatch({ + // type: CHAPTER_DELETED, + // payload: chapter.chapterId, + // }); + // }), + // ); showToast('Chapters deleted'); };