⚡ Bolt: Parallelize sitemap generation across years#135
⚡ Bolt: Parallelize sitemap generation across years#135
Conversation
Replaced sequential await for...of loops over years with Promise.all to fetch session groups and speakers for each year concurrently, reducing build-time waterfalls and speeding up sitemap generation. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request optimizes sitemap generation by parallelizing data fetching across multiple years and concurrently retrieving speakers and talks. It also includes a minor whitespace correction in a test snapshot. Feedback suggests improving observability by logging errors when data fetching fails and simplifying the array flattening logic using the .flat() method.
| getSpeakers(year).catch(() => []), | ||
| getTalks(year).catch(() => []), |
There was a problem hiding this comment.
Silently catching errors with .catch(() => []) can hide potential issues. If getSpeakers or getTalks were ever to change and start throwing errors, those errors would be swallowed without any logs, making debugging difficult. It's better to log the error before returning the default value. While getSpeakers and getTalks currently handle errors internally, this change makes the sitemap generation more robust against future changes to those functions.
getSpeakers(year).catch((err) => {
console.error(`Error fetching speakers for sitemap (year: ${year}):`, err);
return [];
}),
getTalks(year).catch((err) => {
console.error(`Error fetching talks for sitemap (year: ${year}):`, err);
return [];
})| for (const yearUrls of yearUrlsArrays) { | ||
| urls.push(...yearUrls); | ||
| } |
📝 WalkthroughWalkthroughThe sitemap generation in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 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 docstrings
🧪 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/sitemap.ts`:
- Around line 54-58: The Promise.all call wraps getSpeakers(year) and
getTalks(year) with outer .catch(() => []) handlers that swallow errors without
logging; remove those outer .catch wrappers so that getSpeakers and getTalks
handle/log errors themselves and the Promise.all stays as
Promise.all([getSpeakers(year), getTalks(year)]) returning [speakers,
sessionGroups]; locate the Promise.all invocation where getSpeakers and getTalks
are called and delete the .catch(() => []) for each call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 00077ddb-0aea-4a1d-9960-6fdeb777ee5c
⛔ Files ignored due to path filters (1)
__tests__/snapshots/sections/home10/__snapshots__/Section1.test.tsx.snapis excluded by!**/*.snap
📒 Files selected for processing (1)
app/sitemap.ts
| // Parallel fetch speakers and talks for the given year, and catch errors to prevent partial failures from breaking the whole build | ||
| const [speakers, sessionGroups] = await Promise.all([ | ||
| getSpeakers(year).catch(() => []), | ||
| getTalks(year).catch(() => []), | ||
| ]); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
fd -t f -name "useSpeakers.ts" -o -name "useTalks.ts"Repository: anyulled/devbcn-nextjs
Length of output: 296
🏁 Script executed:
git ls-files | grep -E "(hooks|lib)" | head -20Repository: anyulled/devbcn-nextjs
Length of output: 694
🏁 Script executed:
cat -n hooks/useSpeakers.tsRepository: anyulled/devbcn-nextjs
Length of output: 1960
🏁 Script executed:
cat -n hooks/useTalks.tsRepository: anyulled/devbcn-nextjs
Length of output: 5581
🏁 Script executed:
cat -n app/sitemap.ts | sed -n '50,65p'Repository: anyulled/devbcn-nextjs
Length of output: 709
🏁 Script executed:
head -10 app/sitemap.tsRepository: anyulled/devbcn-nextjs
Length of output: 486
Remove the outer catch-all wrappers that lack logging.
getSpeakers and getTalks already catch, log, and return [] in their implementations. The outer .catch(() => []) handlers in sitemap.ts lack logging and violate the guideline: "Avoid unhandled promise rejections. Do not use generic catch-all statements without logging or handling the error properly."
✂️ Proposed fix
- const [speakers, sessionGroups] = await Promise.all([
- getSpeakers(year).catch(() => []),
- getTalks(year).catch(() => []),
- ]);
+ const [speakers, sessionGroups] = await Promise.all([
+ getSpeakers(year),
+ getTalks(year),
+ ]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Parallel fetch speakers and talks for the given year, and catch errors to prevent partial failures from breaking the whole build | |
| const [speakers, sessionGroups] = await Promise.all([ | |
| getSpeakers(year).catch(() => []), | |
| getTalks(year).catch(() => []), | |
| ]); | |
| // Parallel fetch speakers and talks for the given year, and catch errors to prevent partial failures from breaking the whole build | |
| const [speakers, sessionGroups] = await Promise.all([ | |
| getSpeakers(year), | |
| getTalks(year), | |
| ]); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/sitemap.ts` around lines 54 - 58, The Promise.all call wraps
getSpeakers(year) and getTalks(year) with outer .catch(() => []) handlers that
swallow errors without logging; remove those outer .catch wrappers so that
getSpeakers and getTalks handle/log errors themselves and the Promise.all stays
as Promise.all([getSpeakers(year), getTalks(year)]) returning [speakers,
sessionGroups]; locate the Promise.all invocation where getSpeakers and getTalks
are called and delete the .catch(() => []) for each call.
💡 What: Refactored the sitemap generation in
app/sitemap.tsto usePromise.allacross theyearsarray, allowing data fetching for speakers and talks to happen in parallel for all available years rather than sequentially in afor...ofloop.🎯 Why: Previously, the sitemap generated URLs by iterating over each year in sequence and awaiting API calls. This created a significant "waterfall" effect, where the data fetch for 2024 wouldn't begin until 2023 finished. In environments like Next.js App Router static generation, this creates unnecessary build latency.
📊 Impact: Reduces sitemap generation time linearly relative to the number of conference years. By fetching all data in parallel, the total wait time is approximately equal to the single slowest request across all years, instead of the sum of all requests.
🔬 Measurement: You can verify the improvement by running a production build (
npm run build) and observing the time taken to generate the/sitemap.xmlroute before and after this change.PR created automatically by Jules for task 17554748619876484985 started by @anyulled
Summary by CodeRabbit