Skip to content

Conversation

oliveror
Copy link
Member

Merge after #90. This branch is built on #90 (clickable card image) because both change the card <img>; once #90 is merged, this PR shows only its own commits.

Changes

HTTP caching

Resource Cache-Control
Hashed /project2/assets/* public, max-age=31536000, immutable (Apache, deploy/apache.conf)
index.html and other client files no-cache
Public images (/uploads/…) public, no-cache + strong ETag
Private images private, no-cache + strong ETag
GraphQL responses no-store (unchanged)

Upload filenames are UUIDs and never overwritten, so the filename is a safe ETag. The access check still runs on every request, including revalidations, so an image stops showing as soon as its recipe becomes private, while unchanged images are answered with an empty 304 instead of being re-downloaded (previously no-store re-sent every image on every visit).

Server-side image processing (added after team review)

  • Every upload is processed with sharp on the server, whatever the client sent: EXIF auto-rotation, at most 1600 px on the longest side, WebP quality 80. Metadata such as GPS position is not copied (privacy). Quotas count the stored size. Existing files and URLs are unchanged.
  • WebP variants at 480 and 800 px (quality 75) are generated at upload and lazily for older images, cached in UPLOAD_DIR/variants/. Recipe cards and the recipe detail image use srcset/sizes. A seed image goes from 133.6 KB to 18.2 KB at 480 px.
  • Variant lifecycle: every variant request goes through the same authorize() check as the original (so privacy changes apply), cleanup removes variants with the original, and the global storage limit now counts variant files.

Other

  • Fallback image resized to 800 px: 173.4 KB → 51.2 KB (visually identical at card size).
  • sharp 0.34.4 is a new API dependency; the lockfile includes the prebuilt Linux x64 binary used on the deploy runner.

Validation

  • npm run check passes (220 unit tests), incl. new tests for cache headers, 304 revalidation, revalidation after a recipe becomes private, variant widths.
  • test:api (16) against PostgreSQL 16, extended to cover: public/private, no-cache, 304 with If-None-Match, 404 for a stale ETag after the recipe turns private, real variant generation on disk, variant removal by cleanup, and a 3000×2000 JPEG stored as a 1600×1067 WebP.
  • The real-database browser test (upload + display) passes.
  • deploy/apache.conf tested in a real Apache 2.4 container: assets get immutable, index.html / SPA routes / favicon get no-cache.

Remaining work (VM)

  • sudo a2enmod headers, apply deploy/apache.conf, reload Apache. Deploys do not install the Apache config.
  • On the first deploy, check that npm ci --omit=dev installs sharp on the runner (lockfile contains @img/sharp-linux-x64; not testable from here).

AI usage

Written with Claude Code (Anthropic) during the final-delivery review and extended after a teammate's review. Please review the diff as you would any other contribution.

Closes #70

Only the title link opened a recipe; clicking the image did nothing. Wrap
the image in a link to the same page that is hidden from assistive
technology and the tab order, so keyboard and screen-reader users still
get a single link per card. Both links keep the browse state for Back.

Closes #82
- Images: replace Cache-Control no-store with no-cache plus a strong ETag
  (public/private by recipe visibility). The access check still runs on
  every request, so privacy changes apply immediately, but unchanged
  images are answered with an empty 304 instead of being re-downloaded.
- Thumbnails: the API generates 480/800 px WebP variants (?w=) with sharp
  on first request and caches them under UPLOAD_DIR/variants; cleanup
  removes them with the original. Recipe cards use srcset/sizes.
  A seed image goes from 133.6 KB to 18.2 KB at 480 px.
- Apache: immutable one-year caching for hashed /assets, no-cache for
  index.html (deploy/apache.conf, needs mod_headers on the VM).
- Fallback image resized to 800 px: 173.4 KB -> 51.2 KB.
- GraphQL responses keep no-store.

Closes #70
Following team review of #70:
- Every upload is processed with sharp on the server, whatever the client
  sent: EXIF auto-rotation, at most 1600 px on the longest side, WebP
  quality 80, metadata (e.g. GPS) dropped. Quotas use the stored size.
  Existing files and URLs are unchanged.
- Card variants (480/800 px) are built at upload time; older images still
  get them lazily. The recipe detail image now uses srcset/sizes too.
- The global storage limit counts variant files. Variants already go
  through the same authorization (incl. privacy changes) and cleanup.

Refs #70
@oliveror oliveror requested a review from a team as a code owner November 16, 2026 13:58
Copy link
Member

@olestan olestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caching and image processing changes introduce a few regression risks worth addressing before merging:

  • Stale images (imageStore.ts:151–156): Re-seeding overwrites images with stable filenames, but cached variants and ETags remain unchanged. This can cause browsers to display outdated images. Invalidate variants and update ETags when originals change.
  • EXIF orientation (imageStore.ts:158–161): Variants generated from older JPEGs don't apply auto-rotation, potentially displaying images sideways. Add .rotate() and a regression test.
  • Orphaned variants (imageStore.ts:273–298): Cleanup doesn't remove variants when their original files are already missing. These files continue consuming quota and can eventually block uploads.

I'd recommend addressing these cases, particularly cache invalidation and storage accounting, before merging.

Review on #90 was right: the title link's ::after overlay already covers
the whole card, so clicking the image already opened the recipe (checked
in a real browser). The extra aria-hidden image link was redundant and
hid the image alt text from screen readers. Restore RecipeCard as before
and add a browser test that clicks the image centre, since jsdom cannot
hit-test the CSS overlay.

Closes #82
…et-caching

# Conflicts:
#	apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx
Review on #96:
- ETags include the original's size and mtime, and cached variants are
  rebuilt when the original is newer, so re-seeded images (same
  filenames) are never shown stale.
- Variants apply EXIF auto-rotation, so older JPEG uploads stored before
  server-side normalisation are not shown sideways.
- Cleanup removes variants (and interrupted .tmp writes) whose original
  no longer exists, so they stop counting against the storage limit.

Refs #70
@oliveror
Copy link
Member Author

Thanks — all three were real. Fixed in the latest commit:

  • Stale images: the ETag now includes the original's size and modification time ("<file>-<size>-<mtime>[-w480]"), and a cached variant is rebuilt whenever the original is newer. Re-seeding (same filenames) therefore invalidates both. Unit test: a 304 is not sent once the file version changes; store test: replacing the original changes version() and rebuilds the variant.
  • EXIF orientation: the variant pipeline now calls .rotate() first. Store test with a JPEG carrying orientation 6 (200×100 pixels) → variant is 100×200.
  • Orphaned variants: cleanup() now removes variant files (incl. interrupted .tmp writes) whose original no longer exists. API integration test creates an orphan and checks it is removed.

Also merged the updated #90 (the card image link is gone there), so this PR now only adds srcset/sizes to the card image. npm run check (221 unit tests) and test:api pass.

@oliveror oliveror merged commit de09b4a into dev Nov 16, 2026
2 checks passed
oliveror added a commit that referenced this pull request Nov 17, 2026
The recipe page now serves images with srcset width descriptors (#96), and
the browser scales naturalWidth by the chosen density, so the 1x1 test PNG
reported 0 although it loaded. The scenario now uploads a 600x400 PNG, and
calls upload() without the extension argument #96 removed.
@oliveror oliveror deleted the feature/perf-image-asset-caching branch November 17, 2026 00:30
oliveror added a commit that referenced this pull request Nov 17, 2026
…os (#118)

* test(e2e): split the integrated browser test into independent scenarios

The real-API browser test was one 90-second journey, so an early failure
hid everything after it. It is now six independent scenarios (image
upload and removal, editing, rating, saving to the cookbook, privacy and
deletion) plus one short end-to-end journey through the real
registration and publishing UI. Scenario users are created through the
auth service with a real session cookie, because UI registration is rate
limited to 5 per minute per IP, and recipes through the repository.

Closes #108

* test(e2e): restore image, rating-then-save and search regression checks

- The edit scenario now edits a recipe that has an uploaded image and
  checks the same image is still shown, loaded, after reload.
- The rating scenario saves to My Cookbook straight after changing the
  rating, and unsaves/saves straight after removing it; after reload the
  recipe is saved and unrated.
- The journey first searches an unrelated term and waits for the empty
  result (so a loading state cannot pass the check), then finds the recipe
  by title. Verified that ignoring the search term on the server, or
  dropping the image on save, makes the scenarios fail.

* test(e2e): use a realistically sized image in the edit scenario

The recipe page now serves images with srcset width descriptors (#96), and
the browser scales naturalWidth by the chosen density, so the 1x1 test PNG
reported 0 although it loaded. The scenario now uploads a 600x400 PNG, and
calls upload() without the extension argument #96 removed.

* test(e2e): check another user saves the edited recipe; poll image load

Restores the original journey's check that another user can save an
edited recipe and sees its new title in My Cookbook, in the edit
scenario. The upload scenario now polls naturalWidth, as the image can
be visible before it has finished loading.

Refs #108
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants