commit
baac0c384e
|
@ -32,6 +32,7 @@ import { User } from 'types/user';
|
|||
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
||||
import { useMemo } from 'react';
|
||||
import { Collection } from 'types/collection';
|
||||
import { addLogLine } from 'utils/logging';
|
||||
|
||||
const Container = styled('div')`
|
||||
display: block;
|
||||
|
@ -500,12 +501,26 @@ const PhotoFrame = ({
|
|||
index: number,
|
||||
item: EnteFile
|
||||
) => {
|
||||
addLogLine(
|
||||
`[${
|
||||
item.id
|
||||
}] getSlideData called for thumbnail:${!!item.msrc} original:${
|
||||
!!item.msrc && item.src !== item.msrc
|
||||
} inProgress:${fetching[item.id]}`
|
||||
);
|
||||
if (!item.msrc) {
|
||||
addLogLine(`[${item.id}] doesn't have thumbnail`);
|
||||
try {
|
||||
let url: string;
|
||||
if (galleryContext.thumbs.has(item.id)) {
|
||||
addLogLine(
|
||||
`[${item.id}] gallery context cache hit, using cached thumb`
|
||||
);
|
||||
url = galleryContext.thumbs.get(item.id);
|
||||
} else {
|
||||
addLogLine(
|
||||
`[${item.id}] gallery context cache miss, calling downloadManager to get thumb`
|
||||
);
|
||||
if (
|
||||
publicCollectionGalleryContext.accessedThroughSharedURL
|
||||
) {
|
||||
|
@ -530,6 +545,9 @@ const PhotoFrame = ({
|
|||
item.w = newFile.w;
|
||||
item.h = newFile.h;
|
||||
|
||||
addLogLine(
|
||||
`[${item.id}] calling invalidateCurrItems for thumbnail`
|
||||
);
|
||||
try {
|
||||
instance.invalidateCurrItems();
|
||||
if (instance.isOpen()) {
|
||||
|
@ -547,16 +565,23 @@ const PhotoFrame = ({
|
|||
}
|
||||
}
|
||||
if (!fetching[item.id]) {
|
||||
addLogLine(`[${item.id}] new file download fetch original request`);
|
||||
try {
|
||||
fetching[item.id] = true;
|
||||
let urls: { original: string[]; converted: string[] };
|
||||
if (galleryContext.files.has(item.id)) {
|
||||
addLogLine(
|
||||
`[${item.id}] gallery context cache hit, using cached file`
|
||||
);
|
||||
const mergedURL = galleryContext.files.get(item.id);
|
||||
urls = {
|
||||
original: mergedURL.original.split(','),
|
||||
converted: mergedURL.converted.split(','),
|
||||
};
|
||||
} else {
|
||||
addLogLine(
|
||||
`[${item.id}] gallery context cache miss, calling downloadManager to get file`
|
||||
);
|
||||
appContext.startLoading();
|
||||
if (
|
||||
publicCollectionGalleryContext.accessedThroughSharedURL
|
||||
|
@ -608,6 +633,9 @@ const PhotoFrame = ({
|
|||
item.w = newFile.w;
|
||||
item.h = newFile.h;
|
||||
try {
|
||||
addLogLine(
|
||||
`[${item.id}] calling invalidateCurrItems for src`
|
||||
);
|
||||
instance.invalidateCurrItems();
|
||||
if (instance.isOpen()) {
|
||||
instance.updateSize(true);
|
||||
|
@ -617,13 +645,12 @@ const PhotoFrame = ({
|
|||
e,
|
||||
'updating photoswipe after src url update failed'
|
||||
);
|
||||
// ignore
|
||||
throw e;
|
||||
}
|
||||
} catch (e) {
|
||||
logError(e, 'getSlideData failed get src url failed');
|
||||
// no-op
|
||||
} finally {
|
||||
fetching[item.id] = false;
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ import { CustomError } from 'utils/error';
|
|||
import { openThumbnailCache } from './cacheService';
|
||||
import QueueProcessor, { PROCESSING_STRATEGY } from './queueProcessor';
|
||||
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
||||
import { addLogLine } from 'utils/logging';
|
||||
|
||||
const MAX_PARALLEL_DOWNLOADS = 10;
|
||||
|
||||
|
@ -31,11 +32,17 @@ class DownloadManager {
|
|||
|
||||
public async getThumbnail(file: EnteFile) {
|
||||
try {
|
||||
addLogLine(`[${file.id}] [DownloadManager] getThumbnail called`);
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
if (!this.thumbnailObjectURLPromise.get(file.id)) {
|
||||
if (this.thumbnailObjectURLPromise.has(file.id)) {
|
||||
addLogLine(
|
||||
`[${file.id}] [DownloadManager] getThumbnail promise cache hit, returning existing promise`
|
||||
);
|
||||
}
|
||||
if (!this.thumbnailObjectURLPromise.has(file.id)) {
|
||||
const downloadPromise = async () => {
|
||||
const thumbnailCache = await openThumbnailCache();
|
||||
|
||||
|
@ -43,8 +50,14 @@ class DownloadManager {
|
|||
file.id.toString()
|
||||
);
|
||||
if (cacheResp) {
|
||||
addLogLine(
|
||||
`[${file.id}] [DownloadManager] in memory cache hit, using localCache files`
|
||||
);
|
||||
return URL.createObjectURL(await cacheResp.blob());
|
||||
}
|
||||
addLogLine(
|
||||
`[${file.id}] [DownloadManager] in memory cache miss, DownloadManager getThumbnail download started`
|
||||
);
|
||||
const thumb =
|
||||
await this.thumbnailDownloadRequestsProcessor.queueUpRequest(
|
||||
() => this.downloadThumb(token, file)
|
||||
|
@ -65,7 +78,7 @@ class DownloadManager {
|
|||
return await this.thumbnailObjectURLPromise.get(file.id);
|
||||
} catch (e) {
|
||||
this.thumbnailObjectURLPromise.delete(file.id);
|
||||
logError(e, 'get preview Failed');
|
||||
logError(e, 'get DownloadManager preview Failed');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +106,7 @@ class DownloadManager {
|
|||
const fileKey = forPreview ? `${file.id}_preview` : `${file.id}`;
|
||||
try {
|
||||
const getFilePromise = async () => {
|
||||
addLogLine(`[${file.id}] [DownloadManager] downloading file`);
|
||||
const fileStream = await this.downloadFile(file);
|
||||
const fileBlob = await new Response(fileStream).blob();
|
||||
if (forPreview) {
|
||||
|
@ -105,6 +119,11 @@ class DownloadManager {
|
|||
return { converted: [fileURL], original: [fileURL] };
|
||||
}
|
||||
};
|
||||
if (this.fileObjectURLPromise.has(fileKey)) {
|
||||
addLogLine(
|
||||
`[${file.id}] [DownloadManager] getFile promise cache hit, returning existing promise`
|
||||
);
|
||||
}
|
||||
if (!this.fileObjectURLPromise.get(fileKey)) {
|
||||
this.fileObjectURLPromise.set(fileKey, getFilePromise());
|
||||
}
|
||||
|
@ -112,7 +131,7 @@ class DownloadManager {
|
|||
return fileURLs;
|
||||
} catch (e) {
|
||||
this.fileObjectURLPromise.delete(fileKey);
|
||||
logError(e, 'Failed to get File');
|
||||
logError(e, 'download manager Failed to get File');
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@ import { FILE_TYPE } from 'constants/file';
|
|||
import { CustomError } from 'utils/error';
|
||||
import QueueProcessor from './queueProcessor';
|
||||
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
||||
import { addLogLine } from 'utils/logging';
|
||||
|
||||
class PublicCollectionDownloadManager {
|
||||
private fileObjectURLPromise = new Map<
|
||||
|
@ -30,11 +31,17 @@ class PublicCollectionDownloadManager {
|
|||
token: string,
|
||||
passwordToken: string
|
||||
) {
|
||||
addLogLine(`[${file.id}] [PublicDownloadManger] getThumbnail called`);
|
||||
try {
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
if (!this.thumbnailObjectURLPromise.get(file.id)) {
|
||||
if (this.thumbnailObjectURLPromise.has(file.id)) {
|
||||
addLogLine(
|
||||
`[${file.id}] [PublicDownloadManger] getThumbnail promise cache hit, returning existing promise`
|
||||
);
|
||||
}
|
||||
if (!this.thumbnailObjectURLPromise.has(file.id)) {
|
||||
const downloadPromise = async () => {
|
||||
const thumbnailCache = await (async () => {
|
||||
try {
|
||||
|
@ -50,8 +57,14 @@ class PublicCollectionDownloadManager {
|
|||
);
|
||||
|
||||
if (cacheResp) {
|
||||
addLogLine(
|
||||
`[${file.id}] [PublicDownloadManger] in memory cache hit, using localCache files`
|
||||
);
|
||||
return URL.createObjectURL(await cacheResp.blob());
|
||||
}
|
||||
addLogLine(
|
||||
`[${file.id}] [PublicDownloadManger] in memory cache miss, getThumbnail download started`
|
||||
);
|
||||
const thumb =
|
||||
await this.thumbnailDownloadRequestsProcessor.queueUpRequest(
|
||||
() => this.downloadThumb(token, passwordToken, file)
|
||||
|
@ -73,7 +86,7 @@ class PublicCollectionDownloadManager {
|
|||
return await this.thumbnailObjectURLPromise.get(file.id);
|
||||
} catch (e) {
|
||||
this.thumbnailObjectURLPromise.delete(file.id);
|
||||
logError(e, 'get preview Failed');
|
||||
logError(e, 'get publicDownloadManger preview Failed');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +128,9 @@ class PublicCollectionDownloadManager {
|
|||
const fileKey = forPreview ? `${file.id}_preview` : `${file.id}`;
|
||||
try {
|
||||
const getFilePromise = async () => {
|
||||
addLogLine(
|
||||
`[${file.id}] [PublicDownloadManager] downloading file`
|
||||
);
|
||||
const fileStream = await this.downloadFile(
|
||||
token,
|
||||
passwordToken,
|
||||
|
@ -131,6 +147,11 @@ class PublicCollectionDownloadManager {
|
|||
return { converted: [fileURL], original: [fileURL] };
|
||||
}
|
||||
};
|
||||
if (this.fileObjectURLPromise.has(fileKey)) {
|
||||
addLogLine(
|
||||
`[${file.id}] [PublicDownloadManager] getFile promise cache hit, returning existing promise`
|
||||
);
|
||||
}
|
||||
if (!this.fileObjectURLPromise.get(fileKey)) {
|
||||
this.fileObjectURLPromise.set(fileKey, getFilePromise());
|
||||
}
|
||||
|
@ -138,7 +159,7 @@ class PublicCollectionDownloadManager {
|
|||
return fileURLs;
|
||||
} catch (e) {
|
||||
this.fileObjectURLPromise.delete(fileKey);
|
||||
logError(e, 'Failed to get File');
|
||||
logError(e, 'public download manager Failed to get File');
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue