diff --git a/src/common/yt.ts b/src/common/yt.ts index 130f5a6..929eea5 100644 --- a/src/common/yt.ts +++ b/src/common/yt.ts @@ -106,7 +106,7 @@ export const ytService = { if (channelId) return { id: channelId, type: 'channel' }; return null; }, - + /** * @param descriptorsWithIndex YT resource IDs to check * @returns a promise with the list of channels that were found on lbry @@ -163,7 +163,7 @@ export const ytService = { if (!descriptor.id) break url.searchParams.set(urlResolverFunction.paramName, descriptor.id) - const apiResponse = await fetch(url.toString(), { cache: 'force-cache' }); + const apiResponse = await fetch(url.toString(), { cache: 'reload' }); if (!apiResponse.ok) break const value = followResponsePath(await apiResponse.json(), urlResolverFunction.responsePath) if (value) results[descriptor.index] = value @@ -184,7 +184,7 @@ export const ytService = { .filter((descriptorId) => descriptorId) .join(urlResolverFunction.paramArraySeperator) ) - const apiResponse = await fetch(url.toString(), { cache: 'force-cache' }); + const apiResponse = await fetch(url.toString(), { cache: 'reload' }); if (!apiResponse.ok) break const values = followResponsePath(await apiResponse.json(), urlResolverFunction.responsePath) values.forEach((value, index) => { diff --git a/src/scripts/tabOnUpdated.ts b/src/scripts/tabOnUpdated.ts index c3b7fde..62e5f53 100644 --- a/src/scripts/tabOnUpdated.ts +++ b/src/scripts/tabOnUpdated.ts @@ -16,20 +16,25 @@ async function resolveYT(descriptor: YtIdResolverDescriptor) { return segments.join('/'); } +const ctxFromURLIdCache: Record> = {} async function ctxFromURL(href: string): Promise { if (!href) return; - + const url = new URL(href); if (!getSourcePlatfromSettingsFromHostname(url.hostname)) return if (!(url.pathname.startsWith('/watch') || url.pathname.startsWith('/channel'))) return - const { redirect, targetPlatform } = await getExtensionSettingsAsync('redirect', 'targetPlatform'); const descriptor = ytService.getId(href); if (!descriptor) return; // couldn't get the ID, so we're done - const res = await resolveYT(descriptor); // NOTE: API call cached by the browser + // NOTE: API call cached by the browser for the future version + // But cache busting is active for now + // Manual memory cache will be removed later + const promise = ctxFromURLIdCache[descriptor.id] ?? (ctxFromURLIdCache[descriptor.id] = resolveYT(descriptor)) + const res = await promise; if (!res) return; // couldn't find it on lbry, so we're done + const { redirect, targetPlatform } = await getExtensionSettingsAsync('redirect', 'targetPlatform'); return { descriptor, lbryPathname: res, redirect, targetPlatform }; }