From ad7c0000ef209f9f9499ad669234544e918adfcb Mon Sep 17 00:00:00 2001
From: Alan Grainger <16197738+alangrainger@users.noreply.github.com>
Date: Mon, 23 Feb 2026 16:46:53 +1300
Subject: [PATCH 1/2] Improve gallery rendering, make archive creation parallel
---
app/public/web.js | 33 ++++++++++++---------------------
app/src/render.ts | 8 ++++----
app/views/gallery.ejs | 4 ++--
3 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/app/public/web.js b/app/public/web.js
index 8352483..3db4ed6 100644
--- a/app/public/web.js
+++ b/app/public/web.js
@@ -33,24 +33,14 @@ class LGallery {
}, params.lgConfig))
this.items = params.items
- let timeout
- window.addEventListener('scroll', () => {
- if (timeout) clearTimeout(timeout)
- timeout = setTimeout(lgallery.handleScroll, 100)
- })
- lgallery.handleScroll()
- }
-
- /**
- * Listen for scroll events and load more gallery items
- */
- handleScroll () {
- const rect = lgallery.element.getBoundingClientRect()
- const scrollPosition = Math.max(0, rect.bottom - window.innerHeight)
- const buffer = 200 // pixels before bottom to trigger load
-
- if (scrollPosition <= buffer) {
- lgallery.loadMoreItems()
+ const spinner = document.getElementById('loading-spinner')
+ if (spinner) {
+ const observer = new IntersectionObserver((entries) => {
+ if (entries[0].isIntersecting) {
+ lgallery.loadMoreItems(observer, spinner)
+ }
+ }, { rootMargin: '200px' })
+ observer.observe(spinner)
}
}
@@ -58,7 +48,7 @@ class LGallery {
* Load more gallery items as per lightGallery docs
* https://www.lightgalleryjs.com/demos/infinite-scrolling/
*/
- loadMoreItems () {
+ loadMoreItems (observer, spinner) {
if (this.index < this.items.length) {
// Append new thumbnails
this.items
@@ -69,8 +59,9 @@ class LGallery {
this.index += PER_PAGE
this.lightGallery.refresh()
} else {
- // Remove the loading spinner once all items are loaded
- document.getElementById('loading-spinner')?.remove()
+ // Remove the loading spinner and stop observing once all items are loaded
+ observer.disconnect()
+ spinner.remove()
}
}
}
diff --git a/app/src/render.ts b/app/src/render.ts
index 3736e40..2ad2b60 100644
--- a/app/src/render.ts
+++ b/app/src/render.ts
@@ -142,7 +142,7 @@ class Render {
video ? ``,
+ ` data-download="${this.getFilename(asset)}" data-slide-name="${asset.id}">
`,
video ? '' : '',
''
].join('')
@@ -191,7 +191,7 @@ class Render {
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${filename}`)
const archive = archiver('zip', { zlib: { level: 6 } })
archive.pipe(res)
- for (const asset of share.assets) {
+ await Promise.all(share.assets.map(async (asset) => {
const url = immich.buildUrl(immich.apiUrl() + '/assets/' + encodeURIComponent(asset.id) + '/original', {
key: asset.key,
password: asset.password
@@ -200,10 +200,10 @@ class Render {
// Check the response for validity
if (!data.ok) {
console.warn(`Failed to fetch asset: ${asset.id}`)
- continue
+ return
}
archive.append(Buffer.from(await data.arrayBuffer()), { name: this.getFilename(asset) })
- }
+ }))
await archive.finalize()
archive.on('end', () => res.end())
}
diff --git a/app/views/gallery.ejs b/app/views/gallery.ejs
index d86c196..ce073b4 100644
--- a/app/views/gallery.ejs
+++ b/app/views/gallery.ejs
@@ -2,7 +2,7 @@