Documentation
¶
Overview ¶
optimize_images rewrites the receipt photos already on disk (expense receipts and close-shift receipts) into the small WebP form that new uploads get, and updates their DB rows to match. New uploads are handled by api/image_optimize.go; this is the one-off backfill for the older, full-size JPEG/PNG originals.
It is a dry run unless -apply is given. Run it from the API's working directory (where app.env lives and where the relative file_path values in the DB resolve):
go run ./cmd/optimize_images # report what would change go run ./cmd/optimize_images -apply # do it, keeping originals in .orig/
Each rewritten image is written to a new uuid.webp file beside the original and the DB row is repointed with a compare-and-swap on the old file_path, so the run is safe to repeat, safe to interrupt, and safe against a concurrent upload. The original is moved to a .orig/ folder in the same directory (-backup=false deletes it instead); once you've eyeballed the results, reclaim the space with:
find <storage-root> -type d -name .orig -prune -exec rm -rf {} +