-
Notifications
You must be signed in to change notification settings - Fork 302
Add SHA-256 cache to skip already-optimized assets #2730
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
The optimize-assets script now maintains a .optimize-cache.json file that maps image paths to their content hashes. Files whose hash matches the cache are skipped entirely, avoiding redundant sharp processing. The cache is gitignored and persisted across CI runs via actions/cache.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes modify Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
scripts/optimize-assets.js (1)
80-92:⚠️ Potential issue | 🟡 MinorUpdate the “silent” banner or reduce per-file logging.
With the newconsole.log(relative_path), the script no longer runs silently when everything is cached; consider updating the banner or logging only when processing occurs.
🤖 Fix all issues with AI agents
In `@scripts/optimize-assets.js`:
- Around line 9-21: The cache handling in load_cache/save_cache (and the
cache_path/constants like exceptions) must be made versioned and resilient:
introduce a CACHE_VERSION (or config hash) and persist an object like { version:
CACHE_VERSION, entries: {…} } instead of raw entries; update save_cache to write
that envelope, and update load_cache to safely parse JSON inside a try/catch,
verify the stored version equals CACHE_VERSION and if not return a fresh empty
cache (and overwrite on next save); on JSON parse errors treat the cache as
corrupt (optionally back up the file) and return an empty cache so the script
doesn’t crash. Ensure callers that expect the plain cache now use the
envelope.entries shape or adapt load_cache to return entries directly.
- Remove the restore cache step from the tests workflow - Add .optimize-cache.json and remove it from .gitignore - Fix indentation in optimize-assets.js for consistency
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
scripts/optimize-assets.js (1)
80-98:⚠️ Potential issue | 🟡 MinorLogging contradicts the "runs silently" comment.
Line 81 states the script "runs silently if all files are already optimized," but line 92 logs every image file's relative path before the cache check. Consider moving the log after line 98 (i.e., only log files that are actually being processed) or update the comment to reflect the new behavior.
🔧 Proposed fix to log only processed files
- console.log(relative_path); - const file_hash = hash_file(file); if (cache[relative_path] === file_hash) { new_cache[relative_path] = file_hash; continue; } + + console.log(relative_path); const image = sharp(file);
- Persist optimize cache with sorted keys to ensure stable diffs - Add .optimize-cache.json to .prettierignore to prevent noise
The optimize-assets script now maintains a .optimize-cache.json file that maps image paths to their content hashes. Files whose hash matches the cache are skipped entirely, avoiding redundant sharp processing.
The cache is gitignored and persisted across CI runs via actions/cache.
Have you read the Contributing Guidelines on issues?
✅
Summary by CodeRabbit