Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Merge branch 'refactor-in-memory-caching' into add-file-disk-caching

Abhinavdf574d9b392e
diff --cc apps/photos/src/services/download/index.ts
index 07d6019182,f0e14cd167..d6301c1e20
--- a/apps/photos/src/services/download/index.ts
+++ b/apps/photos/src/services/download/index.ts
@@@ -48,12 -48,10 +48,13 @@@ export interface DownloadClient
downloadFileStream: (file: EnteFile) => Promise<Response>;
}
+const FILE_CACHE_LIMIT = 5 * 1024 * 1024 * 1024; // 5GB
+
class DownloadManager {
+ private ready: boolean = false;
private downloadClient: DownloadClient;
private thumbnailCache: LimitedCache;
+ private fileCache: LimitedCache;
private cryptoWorker: Remote<DedicatedCryptoWorker>;
private fileObjectURLPromises = new Map<number, Promise<SourceURLs>>();
@@@ -64,15 -62,29 +65,30 @@@
private progressUpdater: (value: Map<number, number>) => void = () => {};
+ constructor() {
+ const main = async () => {};
+ main();
+ }
+
async init(
app: APPS,
- tokens: { token: string; passwordToken?: string } | { token: string },
+ tokens?: { token: string; passwordToken?: string } | { token: string },
timeout?: number
) {
- this.downloadClient = createDownloadClient(app, tokens, timeout);
- this.thumbnailCache = await openThumbnailCache();
- this.fileCache = await openFileCache();
- this.cryptoWorker = await ComlinkCryptoWorker.getInstance();
+ try {
+ if (this.ready) {
+ addLogLine('DownloadManager already initialized');
+ return;
+ }
+ this.downloadClient = createDownloadClient(app, tokens, timeout);
+ this.thumbnailCache = await openThumbnailCache();
++ this.fileCache = await openFileCache();
+ this.cryptoWorker = await ComlinkCryptoWorker.getInstance();
+ this.ready = true;
+ } catch (e) {
+ logError(e, 'DownloadManager init failed');
+ throw e;
+ }
}
updateToken(token: string, passwordToken?: string) {
@@@ -475,18 -489,9 +513,18 @@@ async function openThumbnailCache()
}
}
+async function openFileCache() {
+ try {
+ return await CacheStorageService.open(CACHES.FILES, FILE_CACHE_LIMIT);
+ } catch (e) {
+ logError(e, 'Failed to open file cache');
+ return null;
+ }
+}
+
function createDownloadClient(
app: APPS,
- tokens: { token: string; passwordToken?: string } | { token: string },
+ tokens?: { token: string; passwordToken?: string } | { token: string },
timeout?: number
): DownloadClient {
if (!timeout) {