Remove indirection

This commit is contained in:
Manav Rathi
2024-04-12 20:58:00 +05:30
parent b056cf7f56
commit a56cf55ffa
3 changed files with 7 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { CacheStorageService, type EnteCache } from "@/next/cache";
import { openCache, type EnteCache } from "@/next/cache";
import log from "@/next/log";
import { APPS } from "@ente/shared/apps/constants";
import ComlinkCryptoWorker from "@ente/shared/crypto";
@@ -513,7 +513,7 @@ export default DownloadManager;
async function openThumbnailCache() {
try {
return await CacheStorageService.open("thumbs");
return await openCache("thumbs");
} catch (e) {
log.error("Failed to open thumbnail cache", e);
if (isInternalUser()) {
@@ -529,7 +529,7 @@ async function openDiskFileCache() {
if (!isElectron()) {
throw Error(CustomError.NOT_AVAILABLE_ON_WEB);
}
return await CacheStorageService.open("files");
return await openCache("files");
} catch (e) {
log.error("Failed to open file cache", e);
if (isInternalUser()) {

View File

@@ -1,4 +1,4 @@
import { CacheStorageService } from "@/next/cache";
import { openCache } from "@/next/cache";
import { BlobOptions } from "types/image";
import {
FaceAlignment,
@@ -54,7 +54,7 @@ async function storeFaceCropForBlob(
) {
const faceCropUrl = `/${faceId}`;
const faceCropResponse = new Response(faceCropBlob);
const faceCropCache = await CacheStorageService.open("face-crops");
const faceCropCache = await openCache("face-crops");
await faceCropCache.put(faceCropUrl, faceCropResponse);
return {
imageUrl: faceCropUrl,

View File

@@ -76,7 +76,7 @@ export interface EnteCache {
* {@link CacheName} which group related data and allow us to use the same key
* across namespaces.
*/
const openCache = async (name: CacheName) =>
export const openCache = async (name: CacheName) =>
globalThis.electron ? openWebCache(name) : openOPFSCacheWeb(name);
/** An implementation of {@link EnteCache} using Web Cache APIs */
@@ -111,14 +111,12 @@ const openOPFSCacheWeb = async (name: CacheName) => {
};
};
export const CacheStorageService = { open: openCache };
export async function cached(
cacheName: CacheName,
id: string,
get: () => Promise<Blob>,
): Promise<Blob> {
const cache = await CacheStorageService.open(cacheName);
const cache = await openCache(cacheName);
const cacheResponse = await cache.match(id);
let result: Blob;