Compare commits
3 Commits
7e53bb5059
...
2dc569256c
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dc569256c | |||
| c7b01b31cb | |||
| 32616d5404 |
+52
-5
@@ -974,6 +974,55 @@ route('PUT', '/api/admin/storage', async ({ req, res }) => {
|
|||||||
|
|
||||||
let previewRebuild = null;
|
let previewRebuild = null;
|
||||||
|
|
||||||
|
/** Progress file, so a restart resumes a run instead of starting it over. */
|
||||||
|
function previewRebuildFile() {
|
||||||
|
return path.join(storageRoot(), 'preview-rebuild.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
function savePreviewRebuild(state) {
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(previewRebuildFile(), JSON.stringify(state));
|
||||||
|
} catch {
|
||||||
|
/* Progress is a convenience; a read-only storage root must not stop a run. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the job and mirrors its progress to disk after every photo. The proxy
|
||||||
|
* rebuild takes hours on a full library, so losing it to a deploy means
|
||||||
|
* starting from the first photo again.
|
||||||
|
*/
|
||||||
|
function beginPreviewRebuild(targets) {
|
||||||
|
const job = startPreviewRebuild({
|
||||||
|
targets,
|
||||||
|
regenerate: (photo) => regenerateRawPreview(photo.id, photo, photoOwner(photo.id) ?? ''),
|
||||||
|
onProgress: (snapshot, pending) =>
|
||||||
|
savePreviewRebuild({ ...snapshot, pending: pending.map((photo) => photo.id) }),
|
||||||
|
});
|
||||||
|
savePreviewRebuild({ ...job.snapshot(), pending: targets.map((photo) => photo.id) });
|
||||||
|
void job.finished.then(() => savePreviewRebuild({ ...job.snapshot(), pending: [] }));
|
||||||
|
previewRebuild = job;
|
||||||
|
return job;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Restarts a run that a restart interrupted, skipping finished photos. */
|
||||||
|
function resumePreviewRebuild() {
|
||||||
|
let saved = null;
|
||||||
|
try {
|
||||||
|
saved = JSON.parse(fs.readFileSync(previewRebuildFile(), 'utf8'));
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (saved?.state !== 'running' || !Array.isArray(saved.pending) || saved.pending.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const byId = new Map(listPhotos().map((photo) => [photo.id, photo]));
|
||||||
|
const targets = saved.pending.map((id) => byId.get(id)).filter(Boolean);
|
||||||
|
if (targets.length === 0) return;
|
||||||
|
console.log(` previews: resuming rebuild, ${targets.length} photo(s) left`);
|
||||||
|
beginPreviewRebuild(targets);
|
||||||
|
}
|
||||||
|
|
||||||
function previewRebuildStatus() {
|
function previewRebuildStatus() {
|
||||||
return (
|
return (
|
||||||
previewRebuild?.snapshot() ?? {
|
previewRebuild?.snapshot() ?? {
|
||||||
@@ -1005,11 +1054,8 @@ route('POST', '/api/admin/previews/rebuild', async ({ req, res }) => {
|
|||||||
const current = previewRebuildStatus();
|
const current = previewRebuildStatus();
|
||||||
if (current.state === 'running') return json(res, 202, { rebuild: current });
|
if (current.state === 'running') return json(res, 202, { rebuild: current });
|
||||||
const targets = previewRebuildTargets(listPhotos());
|
const targets = previewRebuildTargets(listPhotos());
|
||||||
previewRebuild = startPreviewRebuild({
|
const rebuild = beginPreviewRebuild(targets);
|
||||||
targets,
|
json(res, 202, { rebuild: rebuild.snapshot() });
|
||||||
regenerate: (photo) => regenerateRawPreview(photo.id, photo, photoOwner(photo.id) ?? ''),
|
|
||||||
});
|
|
||||||
json(res, 202, { rebuild: previewRebuild.snapshot() });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
route('GET', '/api/quota', async ({ req, res }) => {
|
route('GET', '/api/quota', async ({ req, res }) => {
|
||||||
@@ -2531,6 +2577,7 @@ server.listen(PORT, HOST, async () => {
|
|||||||
);
|
);
|
||||||
console.log(` users: ${users.count()} account(s)${users.count() === 0 ? ' — first signup becomes admin' : ''}`);
|
console.log(` users: ${users.count()} account(s)${users.count() === 0 ? ' — first signup becomes admin' : ''}`);
|
||||||
if (!raw.libraw) console.log(' note: install libraw-wasm for full raw demosaic (embedded previews still work)');
|
if (!raw.libraw) console.log(' note: install libraw-wasm for full raw demosaic (embedded previews still work)');
|
||||||
|
resumePreviewRebuild();
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
*
|
*
|
||||||
* A decode is CPU bound and holds a LibRaw worker for seconds, so the work runs
|
* A decode is CPU bound and holds a LibRaw worker for seconds, so the work runs
|
||||||
* one photo at a time behind a snapshot: a request that blocked for an hour
|
* one photo at a time behind a snapshot: a request that blocked for an hour
|
||||||
* would time out, and decoding in parallel would starve the editor. Progress
|
* would time out, and decoding in parallel would starve the editor. The job
|
||||||
* lives in memory only, so an interrupted rebuild simply starts again.
|
* itself keeps progress in memory; `onProgress` lets the caller persist it so a
|
||||||
|
* restart can pick the run up where it stopped.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Photos that have a proxy worth regenerating: camera raws that still exist. */
|
/** Photos that have a proxy worth regenerating: camera raws that still exist. */
|
||||||
@@ -18,7 +19,7 @@ export function previewRebuildTargets(photos) {
|
|||||||
* A photo that fails is counted and recorded, and the run continues: one
|
* A photo that fails is counted and recorded, and the run continues: one
|
||||||
* unreadable original must not strand the rest of the library.
|
* unreadable original must not strand the rest of the library.
|
||||||
*/
|
*/
|
||||||
export function startPreviewRebuild({ targets, regenerate, now = Date.now }) {
|
export function startPreviewRebuild({ targets, regenerate, now = Date.now, onProgress }) {
|
||||||
const job = {
|
const job = {
|
||||||
state: 'running',
|
state: 'running',
|
||||||
total: targets.length,
|
total: targets.length,
|
||||||
@@ -31,7 +32,7 @@ export function startPreviewRebuild({ targets, regenerate, now = Date.now }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const finished = (async () => {
|
const finished = (async () => {
|
||||||
for (const photo of targets) {
|
for (const [index, photo] of targets.entries()) {
|
||||||
try {
|
try {
|
||||||
const result = await regenerate(photo);
|
const result = await regenerate(photo);
|
||||||
if (result?.sidecar) job.sidecars += 1;
|
if (result?.sidecar) job.sidecars += 1;
|
||||||
@@ -43,6 +44,7 @@ export function startPreviewRebuild({ targets, regenerate, now = Date.now }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
job.done += 1;
|
job.done += 1;
|
||||||
|
onProgress?.({ ...job, errors: [...job.errors] }, targets.slice(index + 1));
|
||||||
}
|
}
|
||||||
job.state = 'done';
|
job.state = 'done';
|
||||||
job.finishedAt = now();
|
job.finishedAt = now();
|
||||||
|
|||||||
@@ -63,6 +63,22 @@ describe('preview rebuild job', () => {
|
|||||||
expect(job.snapshot().errors).toEqual([]);
|
expect(job.snapshot().errors).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reports progress and what is still pending after each photo', async () => {
|
||||||
|
const steps = [];
|
||||||
|
const job = startPreviewRebuild({
|
||||||
|
targets: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
|
||||||
|
regenerate: async () => ({ sidecar: false }),
|
||||||
|
onProgress: (snapshot, pending) =>
|
||||||
|
steps.push({ done: snapshot.done, pending: pending.map((photo) => photo.id) }),
|
||||||
|
});
|
||||||
|
await job.finished;
|
||||||
|
expect(steps).toEqual([
|
||||||
|
{ done: 1, pending: ['b', 'c'] },
|
||||||
|
{ done: 2, pending: ['c'] },
|
||||||
|
{ done: 3, pending: [] },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('finishes immediately when there is nothing to rebuild', async () => {
|
it('finishes immediately when there is nothing to rebuild', async () => {
|
||||||
const job = startPreviewRebuild({ targets: [], regenerate: async () => ({ sidecar: false }) });
|
const job = startPreviewRebuild({ targets: [], regenerate: async () => ({ sidecar: false }) });
|
||||||
await job.finished;
|
await job.finished;
|
||||||
|
|||||||
@@ -94,10 +94,15 @@ export function BasicPanel({
|
|||||||
const [autoBusy, setAutoBusy] = useState(false);
|
const [autoBusy, setAutoBusy] = useState(false);
|
||||||
const [wbBusy, setWbBusy] = useState(false);
|
const [wbBusy, setWbBusy] = useState(false);
|
||||||
|
|
||||||
|
// Raws carry their pixels as a URL, with `thumb` empty; handing the empty
|
||||||
|
// string to the analysis made the decode fail and both Auto buttons quietly
|
||||||
|
// come back with neutral values, so Auto WB matched As shot exactly.
|
||||||
|
const thumbSrc = photo.thumbUrl ?? photo.thumb;
|
||||||
|
|
||||||
const auto = async () => {
|
const auto = async () => {
|
||||||
setAutoBusy(true);
|
setAutoBusy(true);
|
||||||
try {
|
try {
|
||||||
const partial = await computeAutoEdits(photo.thumb);
|
const partial = await computeAutoEdits(thumbSrc);
|
||||||
set(partial, 'Auto tone');
|
set(partial, 'Auto tone');
|
||||||
} finally {
|
} finally {
|
||||||
setAutoBusy(false);
|
setAutoBusy(false);
|
||||||
@@ -107,7 +112,7 @@ export function BasicPanel({
|
|||||||
const autoWb = async () => {
|
const autoWb = async () => {
|
||||||
setWbBusy(true);
|
setWbBusy(true);
|
||||||
try {
|
try {
|
||||||
set(await computeAutoWhiteBalance(photo.thumb), 'Auto white balance');
|
set(await computeAutoWhiteBalance(thumbSrc), 'Auto white balance');
|
||||||
} finally {
|
} finally {
|
||||||
setWbBusy(false);
|
setWbBusy(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2076,6 +2076,7 @@ export class Renderer {
|
|||||||
const data = new Float32Array(w * h * 4);
|
const data = new Float32Array(w * h * 4);
|
||||||
gl.readPixels(0, 0, w, h, gl.RGBA, gl.FLOAT, data);
|
gl.readPixels(0, 0, w, h, gl.RGBA, gl.FLOAT, data);
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||||
|
this.checkDrawError();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2103,9 +2104,35 @@ export class Renderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.checkDrawError();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A rejected draw leaves the canvas untouched, which the editor shows as a
|
||||||
|
* black photo with nothing to explain it. Poll the error queue once per
|
||||||
|
* frame, after the draws are queued, and let the caller report a real
|
||||||
|
* failure instead of painting black.
|
||||||
|
*/
|
||||||
|
private checkDrawError() {
|
||||||
|
const gl = this.gl;
|
||||||
|
const err = gl.getError();
|
||||||
|
if (err === gl.NO_ERROR) return;
|
||||||
|
const name =
|
||||||
|
err === gl.INVALID_OPERATION
|
||||||
|
? 'INVALID_OPERATION'
|
||||||
|
: err === gl.INVALID_VALUE
|
||||||
|
? 'INVALID_VALUE'
|
||||||
|
: err === gl.INVALID_FRAMEBUFFER_OPERATION
|
||||||
|
? 'INVALID_FRAMEBUFFER_OPERATION'
|
||||||
|
: err === gl.OUT_OF_MEMORY
|
||||||
|
? 'OUT_OF_MEMORY'
|
||||||
|
: `0x${err.toString(16)}`;
|
||||||
|
throw new Error(
|
||||||
|
`The photo could not be drawn on this GPU (WebGL ${name}). Reload the page, and if it keeps happening update your graphics driver.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Wait for queued GPU work, e.g. before the canvas is encoded to a file. */
|
/** Wait for queued GPU work, e.g. before the canvas is encoded to a file. */
|
||||||
finishGpu() {
|
finishGpu() {
|
||||||
this.gl.finish();
|
this.gl.finish();
|
||||||
|
|||||||
Reference in New Issue
Block a user