fix(delete_chapter): Excessive number of pending callbacks warn (#481)

* fix(delete_chapter): fix delete all not working

Sometimes there would be "Excessive number of pending callbacks" warn shown.
Removing chapters in batches of 10 (I tried 30 but it was still an issue) seems to work fine now.
TODO: Add some icon about deletion status and make it not lag the entire app.

* fix(delete_chapter): always-coccurent deletion

Make deleting chapters do 3 coccurent deletion at a time making it work similarly to bluebird's `Promise.map(,{coccurent:3})` and removing the `Excessive number of pending callbacks` warn gone.

* Remove unnecesarry console.log
This commit is contained in:
Marcin Majewski
2022-11-26 02:18:53 +01:00
committed by GitHub
parent 383c8f791b
commit 3cb573681f
2 changed files with 51 additions and 10 deletions
+1 -1
View File
@@ -379,7 +379,7 @@ const deleteDownloadedImages = async (
}
}
} catch (error) {
showToast(error.message);
showToast((error as Error).message);
}
};
+50 -9
View File
@@ -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<void>[][]}
*/
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');
};