-
Notifications
You must be signed in to change notification settings - Fork 0
chore(deps): bump up dependencies #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…hing - Add `/api/images/[...path]` to fetch→transcode (WebP)→cache in Cloudflare R2; serve hits with `Cache-Control: public, max-age=31536000, immutable` - Key image cache by Airtable `attachment.id`; update `getImgUrlFromAttachmentObj` - Add R2 client helpers and tag-based GC with throttled ISR runner - Increase revalidation windows (people/projects: 4h; project detail: 6h); default `REVALIDATE_TIME` to 3600s to cut cache misses - Add production-only structured logging to measure Airtable cache misses - Docs: env vars + caching architecture; eslint ignore `**.md`; minor UI class rename ENV: REVALIDATE_TIME=3600, AIRTABLE_LOG=1, R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_BUCKET, R2_CLEANUP_MAX_AGE_DAYS=45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR reduces Airtable API quota pressure by implementing a two-tier caching system for data and images. The changes address frequent ISR revalidation and rotating Airtable attachment URLs that previously caused cache churn.
Key changes:
- Implemented R2-backed image caching with WebP transcoding and stable cache keys
- Extended ISR revalidation windows (People/Projects: 4h, Project detail: 6h) and increased default
REVALIDATE_TIMEfrom 60s to 1h - Added tag-based garbage collection for R2 objects and structured production logging for cache metrics
Reviewed Changes
Copilot reviewed 19 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/app/api/images/[...path]/route.ts | New API route that caches Airtable images in R2 with WebP transcoding |
| src/utils/image-convert.ts | WebP transcoding utility using sharp with HDR→SDR conversion |
| src/lib/r2.ts | R2 client wrapper with helper functions for object operations |
| src/lib/r2-gc.ts | Garbage collector for removing old R2 objects based on access tags |
| src/lib/logger.ts | Structured NDJSON logging for production Airtable fetch metrics |
| src/utils/image.ts | Updated to generate stable local API URLs instead of rotating Airtable URLs |
| src/lib/consts.ts | Added R2 configuration constants and increased default revalidate time |
| src/lib/airtable.ts | Added cache tags and structured logging to track fetch operations |
| src/app/people/page.tsx | Increased revalidation to 4h and integrated R2 cleanup |
| src/app/projects/page.tsx | Increased revalidation to 4h |
| src/app/projects/[id]/page.tsx | Increased revalidation to 6h |
| package.json | Added @aws-sdk/client-s3 and sharp dependencies |
| README.md | Documented new environment variables and caching architecture |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
❌ Build Failed! 🎨 Lint Check✅ Lint: No linting issues found! |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
❌ Build Failed! 🎨 Lint Check✅ Lint: No linting issues found! |
🐛 Bug Fix
📌 Description
This PR fixes two related problems that were causing excessive Airtable API usage and unstable image delivery:
.select().all()calls and repeated downloads of signed Airtable URLs.What changed
Implemented a two-tier cache:
unstable_cachewith per-table tags and a longer defaultREVALIDATE_TIME(1h) so cache misses are the only times the Airtable client runs.attachment.id.Added a tag-based GC (garbage collector) for R2 objects that haven’t been accessed recently, with a throttled ISR entry point.
Introduced production-only structured logging to measure true cache misses and end-to-end latency (for future Airtable quota checking purpose).
🔍 Feature Changes
GET /api/images/{attId}/{variant}/{filename}?src=...routeHighlights
src/app/api/images/[...path]/route.ts:Cache-Control: public, max-age=31536000, immutable.src, transcode to WebP (sharp), store to R2, return WebP.last-access=YYYY-MM-DDfor GC.src/utils/image.ts: image URLs now point to the local API and are keyed byattachment.id, not a rotating signed URL.🔄 Refactor Changes
revalidatewindows to reduce ISR churn (People/Projects → 4h, Project detail → 6h).**.md(keeps lint signal clean for code files)🛠 Bug Fixes
✅ Checklist
Feature Updates:
Bug Fixes:
Code Refactor:
Dependency Updates:
npm audit/pnpm audit.📜 Dependency Changes
@aws-sdk/client-s3sharp📝 Steps to Reproduce (before fix)
revalidate(e.g., 60s), ISR causes frequent server fetches → Airtable quota usage climbs and images are re-downloaded.💬 Additional Notes
Env vars
GC behavior
last-access=YYYY-MM-DD.maybeRunR2CleanupFromISRruns at most once per 24h, deleting objects older than 60d in the current page config (default is 45d if only the env var is used).Operational notes
AIRTABLE_LOG=1) provide:airtable.fetch.start/donewithtable,rows, duration, and cache tag.Files touched (high level)
src/app/api/images/[...path]/route.ts(new)src/lib/r2.ts,src/lib/r2-gc.ts(new)src/utils/image-convert.ts(new),src/utils/image.ts(updated)src/lib/airtable.ts,src/lib/logger.ts(new)people/projectspages updatedeslint.config.mjs,README.md, minor loading shimmer class rename