Skip to content

Conversation

@TorstenDittmann
Copy link
Contributor

@TorstenDittmann TorstenDittmann commented Feb 2, 2026

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

  • Chores
    • Improved asset optimization performance by implementing a caching mechanism to skip reprocessing unchanged files.
    • Enhanced error handling and logging during the optimization process for better transparency.
    • Optimized build workflow to reduce unnecessary reprocessing and improve overall build speed.

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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

Warning

Rate limit exceeded

@TorstenDittmann has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 27 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

Walkthrough

The changes modify scripts/optimize-assets.js to implement a persistent caching system for image optimization. The script now computes SHA-256 hashes of image files and stores optimization results in a .optimize-cache.json file. When processing images, it reuses cached results for unchanged files. Error handling was enhanced for metadata fetching with try/catch blocks. CI-specific behaviors were added, including early stopping after optimization and conditional cache saves. Files with minimal improvement (≤20%) skip rewriting. All processed files are logged with relative paths, and the cache is persisted to disk after processing completes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add SHA-256 cache to skip already-optimized assets' directly and concisely describes the main change: introducing a SHA-256 hashing mechanism to cache optimization results and avoid reprocessing unchanged files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ci-improve-assets-ci

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 | 🟡 Minor

Update the “silent” banner or reduce per-file logging.
With the new console.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
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 | 🟡 Minor

Logging 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
@TorstenDittmann TorstenDittmann merged commit 82c2a9d into main Feb 2, 2026
6 checks passed
@TorstenDittmann TorstenDittmann deleted the ci-improve-assets-ci branch February 2, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants