aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Data/AniList
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-28 08:33:47 +0000
committerFuwn <[email protected]>2026-03-28 08:33:47 +0000
commit64ff00d5b3e93d780f2f3d65eb50595bafc1cb18 (patch)
treec44de213b7d6d541e3d7519d030094af4dd292a5 /src/lib/Data/AniList
parentfix(anilist): fall back to persisted media list cache (diff)
downloaddue.moe-64ff00d5b3e93d780f2f3d65eb50595bafc1cb18.tar.xz
due.moe-64ff00d5b3e93d780f2f3d65eb50595bafc1cb18.zip
fix(anilist): restore completed list filters
Diffstat (limited to 'src/lib/Data/AniList')
-rw-r--r--src/lib/Data/AniList/cacheHydration.ts4
-rw-r--r--src/lib/Data/AniList/media.ts48
2 files changed, 41 insertions, 11 deletions
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<string>(kind),
+ localforage.getItem<string>(cacheStorageKey(kind)),
localforage.getItem<StoredLastPruneTimes>("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<string>(cacheStorageKey(type))
+ ? localforage.getItem<string>(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(