diff options
| author | dax <me@dax.ist> | 2026-08-04 10:26:40 +0000 |
|---|---|---|
| committer | dax <me@dax.ist> | 2026-08-04 10:26:40 +0000 |
| commit | 56b3a602c8e992a2bc197844e1ab3de8743b8012 (patch) | |
| tree | 42e4f1f9ee46e6e8e7bfe93dbaf93608371e65b4 /server.mjs | |
| parent | 8f9b940b875ee854a293c862405dc38ea8b643ff (diff) | |
Code review cleanup: cache placement/adjacency, drop dead code
- Cache choosePlacement and adjacentTile results per (id,dir); invalidate
on addTile. Avoids O(n^3) placement scoring on every pointermove.
- setCurrent now re-renders only affected navs (prev + new) instead of
refreshAllNav; remove refreshAllNav entirely.
- Add pointercancel handler so interrupted touch/trackpad gestures don't
leave a stuck drag.
- Remove dead code: placeRect, photoConnections + /api/photo route and
THUMBS const on server, dangling info var in pointerup.
- Trim .gitignore, remove .DS_Store, bump cache-bust to ?v=20.
Diffstat (limited to 'server.mjs')
| -rw-r--r-- | server.mjs | 62 |
1 files changed, 0 insertions, 62 deletions
@@ -14,7 +14,6 @@ const DB = { } const PORT = Number(process.env.PORT || 3100) -const THUMBS = process.env.THUMBS_ROOT || "/srv/photoprism/storage/cache/thumbnails" const PUBLIC = join(process.cwd(), "public") const MIN_PATH = 3 @@ -182,61 +181,6 @@ function json(res, code, data) { res.end(JSON.stringify(data)) } -async function photoConnections(id) { - const [ph] = await pool.query( - `SELECT p.id, p.photo_title, p.photo_year, p.photo_month, p.photo_day, - f.file_hash, f.file_width, f.file_height - FROM photos p - JOIN files f ON f.photo_id = p.id AND f.file_primary = 1 AND f.file_missing = 0 - WHERE p.id = ?`, - [id] - ) - if (ph.length === 0) return null - const p = ph[0] - const conns = [] - - const [labels] = await pool.query( - `SELECT l.label_name AS name, COUNT(*) AS n - FROM photos_labels pl JOIN labels l ON l.id = pl.label_id - WHERE pl.photo_id = ? GROUP BY pl.label_id`, - [id] - ) - const [keywords] = await pool.query( - `SELECT kw.keyword AS name, COUNT(*) AS n - FROM photos_keywords pk JOIN keywords kw ON kw.id = pk.keyword_id - WHERE pk.photo_id = ? GROUP BY pk.keyword_id`, - [id] - ) - const [camera] = await pool.query( - `SELECT CONCAT(c.camera_make, ' ', c.camera_model) AS name, COUNT(*) AS n - FROM photos p JOIN cameras c ON c.id = p.camera_id WHERE p.id = ?`, - [id] - ) - const [lens] = await pool.query( - `SELECT l.lens_model AS name, COUNT(*) AS n - FROM photos p JOIN lenses l ON l.id = p.lens_id WHERE p.id = ?`, - [id] - ) - - for (const r of labels) conns.push({ type: "label", name: r.name, n: r.n }) - for (const r of keywords) conns.push({ type: "keyword", name: r.name, n: r.n }) - for (const r of camera) conns.push({ type: "camera", name: r.name, n: r.n }) - for (const r of lens) conns.push({ type: "lens", name: r.name, n: r.n }) - - return { - photo: { - id: p.id, - thumb: thumb(p.file_hash), - full: thumb(p.file_hash, BIG_SIZE), - title: p.photo_title || "", - date: p.photo_year ? `${p.photo_year}-${String(p.photo_month || 1).padStart(2, "0")}-${String(p.photo_day || 1).padStart(2, "0")}` : "", - w: p.file_width || 0, - h: p.file_height || 0, - }, - connections: conns, - } -} - const server = http.createServer(async (req, res) => { const url = new URL(req.url, `http://${req.headers.host || "localhost"}`) const path = url.pathname @@ -268,12 +212,6 @@ const server = http.createServer(async (req, res) => { photos, }) } - const photoMatch = path.match(/^\/api\/photo\/(\d+)$/) - if (photoMatch) { - const data = await photoConnections(Number(photoMatch[1])) - if (!data) return json(res, 404, { error: "not found" }) - return json(res, 200, data) - } if (path === "/api/health") return json(res, 200, { ok: true }) if (path === "/" || path === "") { |
