From 6fd259427e46e96eed226b979bcd6e193086c997 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 6 Aug 2026 07:48:43 +0800 Subject: [PATCH] refactor(cache): manage TMDB recognition cache only --- package.json | 2 +- src/api/types.ts | 4 +- .../cache/RecognitionCachePanel.vue | 40 +++++-------------- .../__tests__/RecognitionCachePanel.spec.ts | 21 +++++++++- src/locales/en-US.ts | 4 +- src/locales/zh-CN.ts | 4 +- src/locales/zh-TW.ts | 4 +- 7 files changed, 38 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index b6aff8eb..8a12bdac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moviepilot", - "version": "2.15.4", + "version": "2.15.5", "private": true, "type": "module", "bin": "dist/service.js", diff --git a/src/api/types.ts b/src/api/types.ts index 16f57ab3..e9a3a76b 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1889,9 +1889,7 @@ export interface RecognitionCacheItem { key: string // TMDB ID,0 表示未识别 tmdb_id?: number - // 豆瓣 ID,0 表示未识别 - douban_id?: string | number - // 当前识别数据源对应的统一 ID + // 识别缓存对应的字符串 ID recognition_id?: string // 识别后的标题 title: string diff --git a/src/components/cache/RecognitionCachePanel.vue b/src/components/cache/RecognitionCachePanel.vue index 012b2a62..209f2864 100644 --- a/src/components/cache/RecognitionCachePanel.vue +++ b/src/components/cache/RecognitionCachePanel.vue @@ -11,9 +11,9 @@ import { getDisplayImageUrl } from '@/utils/imageUtils' type RecognitionStatusFilter = 'all' | 'recognized' | 'unrecognized' type InfiniteScrollStatus = 'ok' | 'empty' | 'loading' | 'error' -type RecognitionCacheSource = 'tmdb' | 'douban' const MOBILE_CACHE_PAGE_SIZE = 20 +const RECOGNITION_CACHE_ENDPOINT = 'tmdb/cache' const { t } = useI18n() const display = useDisplay() @@ -22,18 +22,8 @@ const $toast = useToast() const globalSettingsStore = useGlobalSettingsStore() const isMobile = computed(() => display.smAndDown.value) -const recognitionSource = computed(() => - globalSettingsStore.globalSettings.RECOGNIZE_SOURCE === 'douban' ? 'douban' : 'tmdb', -) -const recognitionSourceName = computed(() => - recognitionSource.value === 'douban' - ? t('setting.cache.recognitionSource.douban') - : t('setting.cache.recognitionSource.themoviedb'), -) -const recognitionIdLabel = computed(() => - recognitionSource.value === 'douban' ? t('setting.cache.doubanId') : t('setting.cache.tmdbId'), -) -const recognitionCacheEndpoint = computed(() => `${recognitionSource.value}/cache`) +const recognitionSourceName = computed(() => t('setting.cache.recognitionSource.themoviedb')) +const recognitionIdLabel = computed(() => t('setting.cache.tmdbId')) const recognitionFilterPlaceholder = computed(() => t('setting.cache.filterRecognitionCache', { source: recognitionSourceName.value }), ) @@ -106,12 +96,12 @@ function loadMoreMobileCache({ done }: { done: (status: InfiniteScrollStatus) => done(mobileHasMore.value ? 'ok' : 'empty') } -/** 加载当前识别数据源对应的缓存列表。 */ +/** 加载 TMDB 主识别缓存列表。 */ async function loadCacheData(showSuccess = false) { const requestId = ++cacheLoadRequestId try { loading.value = true - const response = (await api.get(recognitionCacheEndpoint.value)) as unknown as ApiResponse + const response = (await api.get(RECOGNITION_CACHE_ENDPOINT)) as unknown as ApiResponse if (requestId !== cacheLoadRequestId) return const responseData = response.data ?? { count: 0, @@ -139,7 +129,7 @@ async function loadCacheData(showSuccess = false) { } } -/** 清空当前识别数据源的全部识别缓存。 */ +/** 清空全部 TMDB 主识别缓存。 */ async function clearAllCache() { const confirmed = await createConfirm({ type: 'warn', @@ -150,7 +140,7 @@ async function clearAllCache() { try { loading.value = true - const response = (await api.delete(recognitionCacheEndpoint.value)) as unknown as ApiResponse + const response = (await api.delete(RECOGNITION_CACHE_ENDPOINT)) as unknown as ApiResponse if (!response.success) throw new Error(response.message) $toast.success(response.message || t('setting.cache.clearSuccess')) await loadCacheData() @@ -163,10 +153,10 @@ async function clearAllCache() { } } -/** 请求当前识别数据源接口删除指定识别缓存。 */ +/** 请求 TMDB 接口删除指定识别缓存。 */ async function deleteCacheItem(key: string) { const response = (await api.delete( - `${recognitionCacheEndpoint.value}/${encodeURIComponent(key)}`, + `${RECOGNITION_CACHE_ENDPOINT}/${encodeURIComponent(key)}`, )) as unknown as ApiResponse if (!response.success) throw new Error(response.message) } @@ -217,10 +207,9 @@ function getPosterUrl(item: RecognitionCacheItem): string { return getDisplayImageUrl(sourceUrl, globalSettingsStore.globalSettings.GLOBAL_IMAGE_CACHE) } -/** 获取当前识别数据源对应的媒体 ID。 */ +/** 获取识别缓存对应的 TMDB ID。 */ function getRecognitionId(item: RecognitionCacheItem): string { - const recognitionId = recognitionSource.value === 'douban' ? item.douban_id : item.tmdb_id - return recognitionId ? String(recognitionId) : '' + return item.tmdb_id ? String(item.tmdb_id) : '' } /** 判断识别缓存条目是否包含有效媒体 ID。 */ @@ -260,13 +249,6 @@ onMounted(() => { watch([searchFilter, statusFilter], () => { resetMobilePagination() }) - -watch(recognitionSource, () => { - searchFilter.value = '' - statusFilter.value = 'all' - selectedItems.value = [] - void loadCacheData() -})