From 92293c66156e49f801fed6e8cc0996fd88f5f33b Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 3 Sep 2023 18:36:53 -0700
Subject: feat(settings): move last prune times to store

---
 src/lib/List/Due/MangaList.svelte | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'src/lib/List/Due/MangaList.svelte')

diff --git a/src/lib/List/Due/MangaList.svelte b/src/lib/List/Due/MangaList.svelte
index 374d06e1..353d1895 100644
--- a/src/lib/List/Due/MangaList.svelte
+++ b/src/lib/List/Due/MangaList.svelte
@@ -3,11 +3,10 @@
 	import type { UserIdentity, AniListAuthorisation } from '$lib/AniList/identity';
 	import { onDestroy, onMount } from 'svelte';
 	import { chapterCount } from '$lib/mangadex';
-	import chaptersLastPrune from '../../../stores/chaptersLastPrune';
 	import manga from '../../../stores/manga';
 	import { chapterDatabase } from '$lib/chapterDatabase';
-	import mangaLastPrune from '../../../stores/mangaLastPrune';
 	import settings from '../../../stores/settings';
+	import lastPruneTimes from '../../../stores/lastPruneTimes';
 
 	export let user: AniListAuthorisation;
 	export let identity: UserIdentity;
@@ -20,12 +19,12 @@
 	const keyCacher = setInterval(() => {
 		startTime = performance.now();
 		endTime = -1;
-		mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $mangaLastPrune);
+		mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $lastPruneTimes.manga);
 	}, Number($settings.cacheMinutes || 30) * 1000 * 60);
 
 	onMount(async () => {
 		startTime = performance.now();
-		mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $mangaLastPrune);
+		mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $lastPruneTimes.manga);
 	});
 
 	onDestroy(() => {
@@ -40,17 +39,17 @@
 			return [];
 		}
 
-		if ($chaptersLastPrune == '') {
-			chaptersLastPrune.set(new Date().getTime().toString());
+		if ($lastPruneTimes.chapters === 1) {
+			lastPruneTimes.setKey('chapters', new Date().getTime().toString());
 		} else {
 			if (
-				(new Date().getTime() - Number($chaptersLastPrune)) / 1000 / 60 >
+				(new Date().getTime() - $lastPruneTimes.chapters) / 1000 / 60 >
 				Number($settings.cacheMangaMinutes)
 			) {
 				const unresolved = await chapterDatabase.chapters.where('chapters').equals(-1).toArray();
 				const ids = unresolved.map((m) => m.id);
 
-				chaptersLastPrune.set(new Date().getTime().toString());
+				lastPruneTimes.setKey('chapters', new Date().getTime().toString());
 				await chapterDatabase.chapters.bulkDelete(ids);
 			}
 		}
@@ -106,7 +105,14 @@
 	const updateMedia = async (id: number, progress: number | undefined) => {
 		await chapterDatabase.chapters.delete(id);
 		await fetch(`/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
-			mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $mangaLastPrune, true);
+			mangaLists = mediaListCollection(
+				user,
+				identity,
+				Type.Manga,
+				$manga,
+				$lastPruneTimes.manga,
+				true
+			);
 		});
 	};
 </script>
-- 
cgit v1.2.3

