feat: cache shared link (#27889)
parent
79c392ceba
commit
41968fdcac
|
|
@ -1,4 +1,4 @@
|
|||
import { getAssetMediaUrl, setSharedLink } from '$lib/utils';
|
||||
import { getAssetMediaUrl, getSharedLink as getCachedSharedLink, setSharedLink } from '$lib/utils';
|
||||
import { authenticate } from '$lib/utils/auth';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
import { getAssetInfoFromParam } from '$lib/utils/navigation';
|
||||
|
|
@ -28,11 +28,16 @@ export const loadSharedLink = async ({
|
|||
await authenticate(url, { public: true });
|
||||
|
||||
const common = { key, slug };
|
||||
|
||||
const $t = await getFormatter();
|
||||
|
||||
const cachedSharedLink = getCachedSharedLink();
|
||||
const sharedLinkPromise =
|
||||
cachedSharedLink && (key === cachedSharedLink.key || slug === cachedSharedLink.slug)
|
||||
? Promise.resolve(cachedSharedLink)
|
||||
: getMySharedLink({ key, slug });
|
||||
|
||||
try {
|
||||
const [sharedLink, asset] = await Promise.all([getMySharedLink({ key, slug }), getAssetInfoFromParam(params)]);
|
||||
const [sharedLink, asset] = await Promise.all([sharedLinkPromise, getAssetInfoFromParam(params)]);
|
||||
setSharedLink(sharedLink);
|
||||
const assetCount = sharedLink.assets.length;
|
||||
const assetId = sharedLink.album?.albumThumbnailAssetId || sharedLink.assets[0]?.id;
|
||||
|
|
|
|||
Loading…
Reference in New Issue