From 15b7cb2fedfbd2c40ec977092e0e6d2d6cf370dc Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 10 Dec 2023 03:13:05 -0800
Subject: fix(manga): no timeout if cached

---
 src/lib/List/Manga/MangaListTemplate.svelte | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

(limited to 'src/lib/List/Manga/MangaListTemplate.svelte')

diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte
index 54009e50..d730eb51 100644
--- a/src/lib/List/Manga/MangaListTemplate.svelte
+++ b/src/lib/List/Manga/MangaListTemplate.svelte
@@ -74,13 +74,19 @@
 		let finalMedia = releasingMedia;
 		const progressStep = 100 / finalMedia.length;
 		const chapterPromises = finalMedia.map((m: Media) =>
-			// A = On 1 second interval,
-			// B = a maximum of 5 requests per second are allowed.
-			// C = chapterCount makes 3 requests per call.
-			// F = A / (B / C) = 0.6 seconds
-			new Promise((resolve) => setTimeout(resolve, 600)).then(() =>
-				chapterCount(identity, m, $settings.disableGuessing)
-			)
+			chapterDatabase.chapters.get(m.id).then((c) => {
+				if (c !== undefined) {
+					return chapterCount(identity, m, $settings.disableGuessing);
+				} else {
+					// A = On 1 second interval,
+					// B = a maximum of 5 requests per second are allowed.
+					// C = chapterCount makes 3 requests per call.
+					// F = A / (B / C) = 0.6 seconds
+					return new Promise((resolve) => setTimeout(resolve, 600)).then(() =>
+						chapterCount(identity, m, $settings.disableGuessing)
+					);
+				}
+			})
 		);
 		const chapterCounts: (number | null)[] = [];
 
-- 
cgit v1.2.3

