diff options
| author | Fuwn <[email protected]> | 2023-08-27 17:27:43 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-08-27 17:27:43 -0700 |
| commit | 1e0dc85d558b61c14863bf38275b5038bac6abec (patch) | |
| tree | 45a8fc39a7672f732427e946c09d20fd512726a3 /src | |
| parent | feat: cache media (diff) | |
| download | due.moe-1e0dc85d558b61c14863bf38275b5038bac6abec.tar.xz due.moe-1e0dc85d558b61c14863bf38275b5038bac6abec.zip | |
fix(manga): pruning
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/List/Due/MangaList.svelte | 32 | ||||
| -rw-r--r-- | src/stores/chaptersLastPrune.ts | 14 |
2 files changed, 35 insertions, 11 deletions
diff --git a/src/lib/List/Due/MangaList.svelte b/src/lib/List/Due/MangaList.svelte index c7f58819..91524bdc 100644 --- a/src/lib/List/Due/MangaList.svelte +++ b/src/lib/List/Due/MangaList.svelte @@ -3,8 +3,10 @@ import type { UserIdentity, AniListAuthorisation } from '$lib/AniList/identity'; import { onMount } from 'svelte'; import { chapterCount } from '$lib/mangadex'; - import mangaLastPrune from '../../../stores/mangaLastPrune'; + import chaptersLastPrune from '../../../stores/chaptersLastPrune'; import manga from '../../../stores/manga'; + import { chapterDatabase } from '$lib/chapterDatabase'; + import cacheMangaMinutes from '../../../stores/cacheMangaMinutes'; export let user: AniListAuthorisation; export let identity: UserIdentity; @@ -16,7 +18,7 @@ onMount(async () => { startTime = performance.now(); - mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $mangaLastPrune); + mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $chaptersLastPrune); }); const cleanMedia = async (media: object[][], displayUnresolved: boolean) => { @@ -24,13 +26,21 @@ return []; } - // if ($lastPruneAt == '') { - // lastPruneAt.set(new Date().getTime().toString()); - // } else { - // if ((new Date().getTime() - Number($lastPruneAt)) / 1000 / 60 > Number($cacheMangaMinutes)) { - // lastPruneAt.set(new Date().getTime().toString()); - // } - // } + if ($chaptersLastPrune == '') { + chaptersLastPrune.set(new Date().getTime().toString()); + } else { + if ( + (new Date().getTime() - Number($chaptersLastPrune)) / 1000 / 60 > + Number($cacheMangaMinutes) + ) { + const unresolved = await chapterDatabase.chapters.where('chapters').equals(-1).toArray(); + + const ids = unresolved.map((m) => m.id); + + chaptersLastPrune.set(new Date().getTime().toString()); + await chapterDatabase.chapters.bulkDelete(ids); + } + } const flattenedLists = flattenLists(media); const releasingMedia = flattenedLists.filter( @@ -76,7 +86,7 @@ }; const updateMedia = async (id: number, progress: number | undefined) => { - mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $mangaLastPrune); + mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $chaptersLastPrune); await fetch(`/anilist/increment?id=${id}&progress=${progress! + 1}`); }; @@ -88,7 +98,7 @@ <ul><li>Loading ...</li></ul> {:then media} {#await cleanMedia(media, displayUnresolved)} - <summary>Manga</summary> + <summary>Manga [...] <small style="opacity: 50%">...s</small></summary> <ul><li>Loading ...</li></ul> {:then cleanedMedia} diff --git a/src/stores/chaptersLastPrune.ts b/src/stores/chaptersLastPrune.ts new file mode 100644 index 00000000..bccee23e --- /dev/null +++ b/src/stores/chaptersLastPrune.ts @@ -0,0 +1,14 @@ +import { browser } from '$app/environment'; +import { writable } from 'svelte/store'; + +const chaptersLastPrune = writable<string>( + browser ? localStorage.getItem('chaptersLastPrune') ?? '' : '' +); + +chaptersLastPrune.subscribe((value) => { + if (browser) { + localStorage.setItem('chaptersLastPrune', value); + } +}); + +export default chaptersLastPrune; |