From 675a6730e1c86d640dd671be20fa05c53009424b Mon Sep 17 00:00:00 2001 From: Zaida-3dO Date: Mon, 3 Nov 2025 19:01:40 +0000 Subject: [PATCH 1/3] Load assets in parallel When loading the assets in the album, we do so sequentially which is not ideal, particularly on larger albums. This PR loads all assets in parallel instead. --- app/src/render.ts | 80 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/app/src/render.ts b/app/src/render.ts index e2d05b4..e080791 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -105,53 +105,53 @@ class Render { * @param [openItem] - Immediately open a lightbox to the Nth item when the gallery loads */ async gallery (res: Response, share: SharedLink, openItem?: number) { - const items = [] - // publicBaseUrl is used for the og:image, which requires a fully qualified URL. // You can specify this in your docker-compose file, or send it dynamically as a `publicBaseUrl` header const publicBaseUrl = process.env.PUBLIC_BASE_URL || res.req.headers.publicBaseUrl || (res.req.protocol + '://' + res.req.headers.host) - for (const asset of share.assets) { - let video, downloadUrl - if (asset.type === AssetType.video) { - // Populate the data-video property - video = JSON.stringify({ - source: [ - { - src: immich.videoUrl(share.key, asset.id), - type: await immich.getVideoContentType(asset) - } - ], - attributes: { - playsinline: 'playsinline', - controls: 'controls' - } - }) - } - if (getConfigOption('ipp.downloadOriginalPhoto', true)) { - // Add a download link for the original-size image, if configured in config.json - downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) - } + // Use .map to generate an array of promises, then await them all to load in parallel. + const items = await Promise.all(share.assets.map(async (asset) => { + let video, downloadUrl + if (asset.type === AssetType.video) { + // Populate the data-video property + video = JSON.stringify({ + source: [ + { + src: immich.videoUrl(share.key, asset.id), + type: await immich.getVideoContentType(asset) + } + ], + attributes: { + playsinline: 'playsinline', + controls: 'controls' + } + }) + } + if (getConfigOption('ipp.downloadOriginalPhoto', true)) { + // Add a download link for the original-size image, if configured in config.json + downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) + } - const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) - const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) - const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : '' + const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) + const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) + const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : '' - // Create the full HTML element source to pass to the gallery view - const itemHtml = [ - video ? ``, - video ? '
' : '', - '
' - ].join('') + // Create the full HTML element source to pass to the gallery view + const itemHtml = [ + video ? ``, + video ? '
' : '', + '
' + ].join('') - items.push({ - html: itemHtml, - thumbnailUrl - }) - } + return { + html: itemHtml, + thumbnailUrl + }; + })); + res.render('gallery', { items, openItem, From 28455b627624436befacb668912e5b871e20c31b Mon Sep 17 00:00:00 2001 From: Zaida-3dO Date: Mon, 3 Nov 2025 19:08:47 +0000 Subject: [PATCH 2/3] Prettier --- app/src/render.ts | 72 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/render.ts b/app/src/render.ts index e080791..3c0b4b8 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -111,45 +111,45 @@ class Render { // Use .map to generate an array of promises, then await them all to load in parallel. const items = await Promise.all(share.assets.map(async (asset) => { - let video, downloadUrl - if (asset.type === AssetType.video) { - // Populate the data-video property - video = JSON.stringify({ - source: [ - { - src: immich.videoUrl(share.key, asset.id), - type: await immich.getVideoContentType(asset) - } - ], - attributes: { - playsinline: 'playsinline', - controls: 'controls' - } - }) - } - if (getConfigOption('ipp.downloadOriginalPhoto', true)) { - // Add a download link for the original-size image, if configured in config.json - downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) - } + let video, downloadUrl + if (asset.type === AssetType.video) { + // Populate the data-video property + video = JSON.stringify({ + source: [ + { + src: immich.videoUrl(share.key, asset.id), + type: await immich.getVideoContentType(asset) + } + ], + attributes: { + playsinline: 'playsinline', + controls: 'controls' + } + }) + } + if (getConfigOption('ipp.downloadOriginalPhoto', true)) { + // Add a download link for the original-size image, if configured in config.json + downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) + } - const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) - const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) - const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : '' + const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) + const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) + const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : '' - // Create the full HTML element source to pass to the gallery view - const itemHtml = [ - video ? ``, - video ? '
' : '', - '
' - ].join('') + // Create the full HTML element source to pass to the gallery view + const itemHtml = [ + video ? ``, + video ? '
' : '', + '
' + ].join('') - return { - html: itemHtml, - thumbnailUrl - }; + return { + html: itemHtml, + thumbnailUrl + }; })); res.render('gallery', { From a59d798d6d7f061df6c7817afb544280f4950a11 Mon Sep 17 00:00:00 2001 From: Zaida-3dO Date: Mon, 3 Nov 2025 19:10:16 +0000 Subject: [PATCH 3/3] remove whitespace --- app/src/render.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/render.ts b/app/src/render.ts index 3c0b4b8..3968c06 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -112,13 +112,13 @@ class Render { // Use .map to generate an array of promises, then await them all to load in parallel. const items = await Promise.all(share.assets.map(async (asset) => { let video, downloadUrl - if (asset.type === AssetType.video) { + if (asset.type === AssetType.video) { // Populate the data-video property video = JSON.stringify({ source: [ { src: immich.videoUrl(share.key, asset.id), - type: await immich.getVideoContentType(asset) + type: await immich.getVideoContentType(asset) } ], attributes: {