Skip to content

Conversation

@crutch12
Copy link
Contributor

@crutch12 crutch12 commented Dec 2, 2025

Summary

next-sitemap's transform functions calls getAllArticleSlugsWithDates for every /learn/** slug, so it lasts a long time

Fix:

  • added infinite cache for getAllArticleSlugsWithDates() call

To Test

  1. yarn build:cowfi

sitemap.xml should be generated very quickly

Summary by CodeRabbit

Release Notes

  • Refactor
    • Enhanced sitemap generation performance through implementation of efficient caching for article data retrieval.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 2, 2025

@crutch12 is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Walkthrough

Introduces an in-memory caching wrapper for asynchronous functions in the sitemap configuration. A cached variant of getAllArticleSlugsWithDates is created and integrated into sitemap generation. Cache stores successful results and clears on error to enable retries.

Changes

Cohort / File(s) Summary
Async caching wrapper
apps/cow-fi/next-sitemap.config.js
Added cacheAsyncFunction utility for in-memory caching of async results. Created getAllArticleSlugsWithDatesCached wrapper around getAllArticleSlugsWithDates. Updated sitemap transform to use cached variant. Cache persists on success, clears on rejection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify cache initialization and state management within the wrapper
  • Confirm error handling properly clears cache to allow retries
  • Check for potential memory implications of indefinite cache retention without expiration logic

Poem

🐰 A cache now whispers through the sitemap's halls,
Remember each article, quick as a call—
First time we gather with diligent care,
Then zip! Return cached—swift as a hare! ✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a cache for the getAllArticleSlugsWithDates() function in the sitemap configuration.
Description check ✅ Passed The description covers the problem, solution, and testing steps, but lacks detail on background context and visual/manual verification specifics required by the template.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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: 0

🧹 Nitpick comments (1)
apps/cow-fi/next-sitemap.config.js (1)

54-68: Arguments accepted but not used for cache keying.

The function signature accepts ...args, but the implementation caches a single result globally without considering the arguments. If this wrapper is ever used with a function that takes different arguments, it will incorrectly return the cached result from the first call regardless of argument values.

For the current use case (wrapping a zero-argument function), this works correctly. However, the misleading signature could cause bugs if reused elsewhere.

Consider one of these approaches:

Option 1 (simpler): Remove ...args to make the intent explicit:

-function cacheAsyncFunction(fn) {
+function cacheZeroArgAsyncFunction(fn) {
   const EMPTY = Symbol()
   let result = EMPTY
 
-  return async function (...args) {
+  return async function () {
     if (result !== EMPTY) return result
 
-    result = fn(...args).catch((err) => {
+    result = fn().catch((err) => {
       result = EMPTY
       throw err
     })
 
     return result
   }
 }

Option 2 (more flexible): Implement proper argument-based cache keying using a Map with serialized keys, but this adds complexity that may not be needed for this use case.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce4d7e3 and 8c45f18.

📒 Files selected for processing (1)
  • apps/cow-fi/next-sitemap.config.js (2 hunks)
🔇 Additional comments (2)
apps/cow-fi/next-sitemap.config.js (2)

70-71: LGTM!

The type annotation correctly preserves the function signature, and the cached wrapper is appropriately applied to optimize sitemap generation performance.


25-25: LGTM!

Correctly switched to the cached variant, which will prevent repeated expensive CMS API calls during sitemap generation for multiple /learn/* pages.

@elena-zh elena-zh requested a review from a team December 3, 2025 10:45
Copy link
Collaborator

@shoom3301 shoom3301 left a comment

Choose a reason for hiding this comment

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

Awesome! Thank you!

@shoom3301 shoom3301 merged commit 92bf558 into cowprotocol:develop Dec 5, 2025
8 of 15 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants