From 56f1d3cca27dcc8fc7eeccc9126ecb75218516c6 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Sat, 10 Dec 2022 18:30:25 +0100 Subject: [PATCH] speed improvements --- src/lib/components/anilistItems.svelte | 10 +++++ src/lib/util/anilist.ts | 4 +- src/routes/[manga]/+page.svelte | 53 ++++++++++++++------------ 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/lib/components/anilistItems.svelte b/src/lib/components/anilistItems.svelte index 9a0bdaf..7fed702 100644 --- a/src/lib/components/anilistItems.svelte +++ b/src/lib/components/anilistItems.svelte @@ -8,6 +8,13 @@ var isLoading = false; async function find(entry) { + if(typeof localStorage !== "undefined") { + let cache = localStorage.getItem("anilist-mangadex-" + entry.media.id); + if(cache) { + goto("./" + cache); + return; + } + } isLoading = true; var query = new URLSearchParams(); query.set("title", entry.media.title.romaji); @@ -33,6 +40,9 @@ isLoading = false; return } + if(typeof localStorage !== "undefined") { + localStorage.setItem("anilist-mangadex-" + entry.media.id, item.id); + } goto("./" + item.id); } diff --git a/src/lib/util/anilist.ts b/src/lib/util/anilist.ts index 2711f33..d95f77d 100644 --- a/src/lib/util/anilist.ts +++ b/src/lib/util/anilist.ts @@ -70,9 +70,11 @@ export function getUserDetails() { return data; } +let mangaCache; export function getUserManga() { const id = getUserID(); - return makeRequest(` + if(mangaCache) return mangaCache; + return mangaCache = makeRequest(` query($id: Int) { MediaListCollection(userId: $id, type: MANGA) { lists { diff --git a/src/routes/[manga]/+page.svelte b/src/routes/[manga]/+page.svelte index 9bf754a..1e680d8 100644 --- a/src/routes/[manga]/+page.svelte +++ b/src/routes/[manga]/+page.svelte @@ -246,33 +246,36 @@ } } + const anilistCache = new Map(); function anilistInfo(id) { - return makeRequest(` - query ($id: Int) { - Media(id: $id, format: MANGA) { - id - type - format - status - chapters - volumes - countryOfOrigin - bannerImage - genres - synonyms - averageScore - popularity - isFavourite - isFavouriteBlocked - isAdult - siteUrl - coverImage { - large - medium - color + if(!anilistCache.has(id)) + anilistCache.set(id, makeRequest(` + query ($id: Int) { + Media(id: $id, format: MANGA) { + id + type + format + status + chapters + volumes + countryOfOrigin + bannerImage + genres + synonyms + averageScore + popularity + isFavourite + isFavouriteBlocked + isAdult + siteUrl + coverImage { + large + medium + color + } } - } - }`, { id }).then(t => t.data.Media); + }`, { id }).then(t => t.data.Media)); + return anilistCache.get(id); } let anilistData;