From 64ff00d5b3e93d780f2f3d65eb50595bafc1cb18 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 28 Mar 2026 08:33:47 +0000 Subject: fix(anilist): restore completed list filters --- src/lib/Data/AniList/cacheHydration.ts | 4 ++- src/lib/Data/AniList/media.ts | 48 +++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 11 deletions(-) (limited to 'src/lib/Data') diff --git a/src/lib/Data/AniList/cacheHydration.ts b/src/lib/Data/AniList/cacheHydration.ts index 434d2a82..ac3b4d72 100644 --- a/src/lib/Data/AniList/cacheHydration.ts +++ b/src/lib/Data/AniList/cacheHydration.ts @@ -6,6 +6,8 @@ import localforage from "localforage"; type MediaCacheKind = "anime" | "manga"; +const cacheStorageKey = (kind: MediaCacheKind) => `${kind}:v2`; + interface StoredLastPruneTimes { anime: number; chapters: number; @@ -32,7 +34,7 @@ export const hydrateMediaListCache = (kind: MediaCacheKind) => { const promise = (async () => { const [cache, pruneTimes] = await Promise.all([ - localforage.getItem(kind), + localforage.getItem(cacheStorageKey(kind)), localforage.getItem("lastPruneTimes"), ]); diff --git a/src/lib/Data/AniList/media.ts b/src/lib/Data/AniList/media.ts index 55263207..fee23113 100644 --- a/src/lib/Data/AniList/media.ts +++ b/src/lib/Data/AniList/media.ts @@ -212,7 +212,7 @@ interface CollectionOptions { const assignDefaultOptions = (options: CollectionOptions) => { const nonNullOptions: CollectionOptions = { - includeCompleted: false, + includeCompleted: true, forcePrune: false, all: false, addNotification: undefined, @@ -250,17 +250,36 @@ const collectionKey = ( includeRelations: options.includeRelations, }); -const cacheStorageKey = (type: Type) => - type === Type.Anime ? "anime" : "manga"; +const usesSharedMediaStore = (options: CollectionOptions) => + !!options.includeCompleted && !options.all && !options.includeRelations; + +const cacheStorageKey = (type: Type, options: CollectionOptions) => { + const baseKey = type === Type.Anime ? "anime:v2" : "manga:v2"; + + if (usesSharedMediaStore(options)) return baseKey; + + return [ + baseKey, + options.includeCompleted ? "completed" : "default", + options.all ? "all" : "scoped", + options.includeRelations ? "relations" : "plain", + ].join(":"); +}; const hydrateCollectionInputs = async ( type: Type, + options: CollectionOptions, mediaCache: string | undefined, currentLastPruneAt: string | number, ) => { if (!browser) return { mediaCache, currentLastPruneAt }; - const shouldReadStoredCache = mediaCache === undefined || mediaCache === ""; + if (!usesSharedMediaStore(options)) mediaCache = ""; + + const shouldReadStoredCache = + !usesSharedMediaStore(options) || + mediaCache === undefined || + mediaCache === ""; const shouldReadStoredPruneTime = String(currentLastPruneAt) === "" || Number(currentLastPruneAt) <= 1; @@ -269,7 +288,7 @@ const hydrateCollectionInputs = async ( const [storedCache, storedPruneTimes] = await Promise.all([ shouldReadStoredCache - ? localforage.getItem(cacheStorageKey(type)) + ? localforage.getItem(cacheStorageKey(type, options)) : Promise.resolve(null), shouldReadStoredPruneTime ? localforage.getItem<{ @@ -310,6 +329,7 @@ export const mediaListCollection = async ( const currentCacheMinutes = settings.get().cacheMinutes; const hydratedInputs = await hydrateCollectionInputs( type, + options, mediaCache, currentLastPruneAt, ); @@ -329,10 +349,12 @@ export const mediaListCollection = async ( ) { if (type === Type.Anime) { lastPruneTimes.setKey("anime", new Date().getTime()); - anime.set(""); + + if (usesSharedMediaStore(options)) anime.set(""); } else { lastPruneTimes.setKey("manga", new Date().getTime()); - manga.set(""); + + if (usesSharedMediaStore(options)) manga.set(""); } mediaCache = ""; @@ -374,9 +396,15 @@ export const mediaListCollection = async ( options.all, ); - if (mediaCache === "") - if (type === Type.Anime) anime.set(JSON.stringify(flattened)); - else manga.set(JSON.stringify(flattened)); + if (mediaCache === "") { + const serialized = JSON.stringify(flattened); + + if (usesSharedMediaStore(options)) { + if (type === Type.Anime) anime.set(serialized); + else manga.set(serialized); + } else if (browser) + await localforage.setItem(cacheStorageKey(type, options), serialized); + } if (options.addNotification) options.addNotification( -- cgit v1.2.3