aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-03 18:36:53 -0700
committerFuwn <[email protected]>2023-09-03 18:36:53 -0700
commit92293c66156e49f801fed6e8cc0996fd88f5f33b (patch)
tree155c66f6103987a88ddcde2af46ee7c79cc47177 /src/lib
parentfix(media): cache minutes from settings (diff)
downloaddue.moe-92293c66156e49f801fed6e8cc0996fd88f5f33b.tar.xz
due.moe-92293c66156e49f801fed6e8cc0996fd88f5f33b.zip
feat(settings): move last prune times to store
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/AniList/media.ts11
-rw-r--r--src/lib/List/Due/AnimeList.svelte22
-rw-r--r--src/lib/List/Due/MangaList.svelte24
-rw-r--r--src/lib/List/UpcomingAnimeList.svelte4
4 files changed, 40 insertions, 21 deletions
diff --git a/src/lib/AniList/media.ts b/src/lib/AniList/media.ts
index 034fccfd..ebf8c72f 100644
--- a/src/lib/AniList/media.ts
+++ b/src/lib/AniList/media.ts
@@ -2,9 +2,8 @@ import type { AniListAuthorisation } from '$lib/AniList/identity';
import type { UserIdentity } from './identity';
import anime from '../../stores/anime';
import manga from '../../stores/manga';
-import mangaLastPrune from '../../stores/mangaLastPrune';
-import animeLastPrune from '../../stores/animeLastPrune';
import settings from '../../stores/settings';
+import lastPruneTimes from '../../stores/lastPruneTimes';
export enum Type {
Anime,
@@ -69,9 +68,9 @@ export const mediaListCollection = async (
if (String(currentLastPruneAt) == '') {
if (type === Type.Anime) {
- animeLastPrune.set(new Date().getTime().toString());
+ lastPruneTimes.setKey('anime', new Date().getTime().toString());
} else {
- mangaLastPrune.set(new Date().getTime().toString());
+ lastPruneTimes.setKey('manga', new Date().getTime().toString());
}
} else {
if (
@@ -80,10 +79,10 @@ export const mediaListCollection = async (
forcePrune
) {
if (type === Type.Anime) {
- animeLastPrune.set(new Date().getTime().toString());
+ lastPruneTimes.setKey('anime', new Date().getTime().toString());
anime.set('');
} else {
- mangaLastPrune.set(new Date().getTime().toString());
+ lastPruneTimes.setKey('manga', new Date().getTime().toString());
manga.set('');
}
diff --git a/src/lib/List/Due/AnimeList.svelte b/src/lib/List/Due/AnimeList.svelte
index 1409730f..f70363f3 100644
--- a/src/lib/List/Due/AnimeList.svelte
+++ b/src/lib/List/Due/AnimeList.svelte
@@ -5,8 +5,8 @@
import type { UserIdentity, AniListAuthorisation } from '$lib/AniList/identity';
import { onDestroy, onMount } from 'svelte';
import anime from '../../../stores/anime';
- import animeLastPrune from '../../../stores/mangaLastPrune';
import settings from '../../../stores/settings';
+ import lastPruneTimes from '../../../stores/lastPruneTimes';
export let user: AniListAuthorisation;
export let identity: UserIdentity;
@@ -19,12 +19,19 @@
const keyCacher = setInterval(() => {
startTime = performance.now();
endTime = -1;
- animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $animeLastPrune, true);
+ animeLists = mediaListCollection(
+ user,
+ identity,
+ Type.Anime,
+ $anime,
+ $lastPruneTimes.anime,
+ true
+ );
}, Number($settings.cacheMinutes || 10) * 1000 * 60);
onMount(async () => {
startTime = performance.now();
- animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $animeLastPrune);
+ animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime);
});
onDestroy(() => {
@@ -133,7 +140,14 @@
const updateMedia = async (id: number, progress: number | undefined) => {
fetch(`/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
- animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $animeLastPrune, true);
+ animeLists = mediaListCollection(
+ user,
+ identity,
+ Type.Anime,
+ $anime,
+ $lastPruneTimes.anime,
+ true
+ );
});
};
</script>
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>
diff --git a/src/lib/List/UpcomingAnimeList.svelte b/src/lib/List/UpcomingAnimeList.svelte
index 88b2cca0..87343032 100644
--- a/src/lib/List/UpcomingAnimeList.svelte
+++ b/src/lib/List/UpcomingAnimeList.svelte
@@ -5,7 +5,7 @@
import type { UserIdentity, AniListAuthorisation } from '$lib/AniList/identity';
import { onMount } from 'svelte';
import anime from '../../stores/anime';
- import animeLastPrune from '../../stores/mangaLastPrune';
+ import lastPruneTimes from '../../stores/lastPruneTimes';
export let user: AniListAuthorisation;
export let identity: UserIdentity;
@@ -17,7 +17,7 @@
onMount(async () => {
startTime = performance.now();
- animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $animeLastPrune);
+ animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime);
});
const cleanMedia = (media: { entries: { media: Media }[] }[], displayUnresolved: boolean) => {