Files
CatoandClaude cb9dea9e21 Place photos drain from the database into R2, by the app itself (#621)
- With a bucket configured nothing writes place_photo_bytes: the keep is the
  bucket over the database read only. The share card reads the bucket only.
- Object keys are place-photos/v2/<sha256(file) 24 hex>/<width>: [0-9a-z/]
  only, so the public address needs no decoding. An object under the old raw
  key is copied to its current key inside the bucket on first read.
- photo-drain.ts, started from src/instrumentation.ts under a Postgres
  advisory lock: batches of 8 at about 512 kB/s (PHOTO_DRAIN_KBPS), each row
  deleted only after a HEAD shows the same length, content type and MD5;
  errors back off doubling to 15 minutes; the empty table is TRUNCATEd
  under an exclusive lock and only if still empty, and where the role may
  not, the result is measured and left to autovacuum. /api/health shows the
  progress (placePhotos). PHOTO_DRAIN=0 stops it.
- Pages draw a place photograph straight from the bucket only when a public
  base is set and the bucket is known to hold that photograph at that width
  (an index from a listing every 15 minutes plus every write); otherwise the
  route. PLACE_PHOTOS_DIRECT=0 is now only a kill switch.
- Dropping the empty table stays manual: Loki's apply-schema.sh refuses any
  pending DROP TABLE and aborts the deploy (AGENTS.md, "Photos").


Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 14:10:56 +01:00
..