From bc2eb7307ff30506b6529d8bab1b295c805f3ed3 Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Tue, 18 Aug 2026 15:34:10 -0400 Subject: [PATCH] =?UTF-8?q?perf:=20indexes,=20query=20rewrites,=20caching?= =?UTF-8?q?=20=E2=80=94=20fix=20slow=20load=20at=2030k+=20photos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Expression index on strftime('%m-%d', date_taken) makes Memories instant - Composite indexes: (deleted, date_taken), (deleted, starred), (deleted, media_type), (deleted, place_city), (deleted, camera_model), (collection_id, photo_id) - Albums: replace window-function queries with GROUP BY + MAX(id) CTE — avoids materialising 30k rows × 3 times just to pick cover photos - Library stats + Albums: 30s/60s in-memory cache, invalidated on any write - Videos: cursor-based pagination (100/page) with IntersectionObserver infinite scroll - Fix build error: mixed ?? and || operators in MemoriesView track count display Co-Authored-By: Claude Sonnet 4.6 --- client/src/api/photos.js | 9 +- client/src/components/MemoriesView.jsx | 2 +- client/src/components/VideosView.jsx | 71 +++++++++--- server/index.js | 143 ++++++++++++++++++------- worker/db.js | 13 +++ 5 files changed, 180 insertions(+), 58 deletions(-) diff --git a/client/src/api/photos.js b/client/src/api/photos.js index aeba49d..e81aa15 100644 --- a/client/src/api/photos.js +++ b/client/src/api/photos.js @@ -115,11 +115,12 @@ export function fetchVideoStats() { return api('/api/videos/stats'); } -export function fetchVideos({ from, to, city } = {}) { +export function fetchVideos({ from, to, city, cursor } = {}) { const p = new URLSearchParams(); - if (from) p.set('from', from); - if (to) p.set('to', to); - if (city) p.set('city', city); + if (from) p.set('from', from); + if (to) p.set('to', to); + if (city) p.set('city', city); + if (cursor) p.set('cursor', cursor); const qs = p.toString(); return api(`/api/videos${qs ? '?' + qs : ''}`); } diff --git a/client/src/components/MemoriesView.jsx b/client/src/components/MemoriesView.jsx index b5f4017..d00ccb3 100644 --- a/client/src/components/MemoriesView.jsx +++ b/client/src/components/MemoriesView.jsx @@ -347,7 +347,7 @@ export default function MemoriesView() { {scanInfo && (
- {scanInfo.scanning ? '⟳ Scanning music…' : scanInfo.enabled ? `${(scanInfo.total ?? tracks.length || scanInfo.count).toLocaleString()} tracks` : ''} + {scanInfo.scanning ? '⟳ Scanning music…' : scanInfo.enabled ? `${scanInfo.count.toLocaleString()} tracks` : ''} {scanInfo.enabled && !scanInfo.scanning && (