🍣 added back memory cache temporarily

- added back manual memory cache temporarily
- and this time its working as expected
- also disabled use of browser cache for now
- thought we are still saying browser to cache it for the future version
This commit is contained in:
Shiba 2022-01-08 23:32:49 +00:00
parent c2aacaf307
commit 73508ff532
2 changed files with 11 additions and 6 deletions

View file

@ -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<string>(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<string[]>(await apiResponse.json(), urlResolverFunction.responsePath)
values.forEach((value, index) => {

View file

@ -16,20 +16,25 @@ async function resolveYT(descriptor: YtIdResolverDescriptor) {
return segments.join('/');
}
const ctxFromURLIdCache: Record<string, Promise<string | undefined>> = {}
async function ctxFromURL(href: string): Promise<UpdateContext | void> {
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 };
}