refactor(mal): complete removal of all ID mapping caching

This commit is contained in:
paregi12 2026-03-20 00:36:36 +05:30
parent 0108fd119f
commit fc2c698383

View file

@ -7,11 +7,7 @@ import { ArmSyncService } from './ArmSyncService';
import { logger } from '../../utils/logger'; import { logger } from '../../utils/logger';
import axios from 'axios'; import axios from 'axios';
const MAPPING_PREFIX = 'mal_map_'; // MalSync.ts
const getTitleCacheKey = (title: string, type: 'movie' | 'series', season = 1) =>
`${MAPPING_PREFIX}${title.trim()}_${type}_${season}`;
const getLegacyTitleCacheKey = (title: string, type: 'movie' | 'series') =>
`${MAPPING_PREFIX}${title.trim()}_${type}`;
export const MalSync = { export const MalSync = {
/** /**
@ -387,13 +383,10 @@ export const MalSync = {
} }
for (const item of allItems) { for (const item of allItems) {
const type = item.node.media_type === 'movie' ? 'movie' : 'series'; // No longer populating mapping cache here to prevent season mismatches.
const title = item.node.title.trim(); // Logic is now real-time based on air dates.
mmkvStorage.setNumber(getTitleCacheKey(title, type, 1), item.node.id);
// Keep legacy key for backwards compatibility with old cache readers.
mmkvStorage.setNumber(getLegacyTitleCacheKey(title, type), item.node.id);
} }
console.log(`[MalSync] Synced ${allItems.length} items to mapping cache.`); console.log(`[MalSync] Synced ${allItems.length} items from MAL.`);
// If auto-sync to library is enabled, also add 'watching' items to Nuvio Library // If auto-sync to library is enabled, also add 'watching' items to Nuvio Library
if (mmkvStorage.getBoolean('mal_auto_sync_to_library') ?? false) { if (mmkvStorage.getBoolean('mal_auto_sync_to_library') ?? false) {
@ -451,26 +444,10 @@ export const MalSync = {
} }
}, },
/**
* Manually map an ID if auto-detection fails
*/
setMapping: (title: string, malId: number, type: 'movie' | 'series' = 'series', season: number = 1) => {
const cleanTitle = title.trim();
mmkvStorage.setNumber(getTitleCacheKey(cleanTitle, type, season), malId);
// Keep legacy key for compatibility.
mmkvStorage.setNumber(getLegacyTitleCacheKey(cleanTitle, type), malId);
},
/** /**
* Get external IDs (IMDb, etc.) and season info from a MAL ID using MalSync API * Get external IDs (IMDb, etc.) and season info from a MAL ID using MalSync API
*/ */
getIdsFromMalId: async (malId: number): Promise<{ imdbId: string | null; season: number }> => { getIdsFromMalId: async (malId: number): Promise<{ imdbId: string | null; season: number }> => {
const cacheKey = `mal_ext_ids_v2_${malId}`;
const cached = mmkvStorage.getString(cacheKey);
if (cached) {
return JSON.parse(cached);
}
try { try {
const response = await axios.get(`https://api.malsync.moe/mal/anime/${malId}`); const response = await axios.get(`https://api.malsync.moe/mal/anime/${malId}`);
const data = response.data; const data = response.data;
@ -486,9 +463,7 @@ export const MalSync = {
} }
} }
const result = { imdbId, season }; return { imdbId, season };
mmkvStorage.setString(cacheKey, JSON.stringify(result));
return result;
} catch (e) { } catch (e) {
console.error('[MalSync] Failed to fetch external IDs:', e); console.error('[MalSync] Failed to fetch external IDs:', e);
} }