fix: same SearchResult

This commit is contained in:
shinya
2025-07-13 12:40:25 +08:00
parent 3c8f316ad7
commit ce8a01c577
2 changed files with 10 additions and 43 deletions

View File

@@ -1,7 +1,8 @@
/* eslint-disable no-console */
import { db } from '@/lib/db';
import { type VideoDetail, fetchVideoDetail } from '@/lib/fetchVideoDetail';
import { fetchVideoDetail } from '@/lib/fetchVideoDetail';
import { SearchResult } from '@/lib/types';
const STORAGE_TYPE = process.env.NEXT_PUBLIC_STORAGE_TYPE ?? 'localstorage';
@@ -16,14 +17,14 @@ async function refreshRecordAndFavorites() {
users.push(process.env.USERNAME);
}
// 函数级缓存key 为 `${source}+${id}`,值为 Promise<VideoDetail | null>
const detailCache = new Map<string, Promise<VideoDetail | null>>();
const detailCache = new Map<string, Promise<SearchResult | null>>();
// 获取详情 Promise带缓存和错误处理
const getDetail = async (
source: string,
id: string,
fallbackTitle: string
): Promise<VideoDetail | null> => {
): Promise<SearchResult | null> => {
const key = `${source}+${id}`;
let promise = detailCache.get(key);
if (!promise) {