Files
blog-eleventy-indiekit/_data/githubStarred.js
Ricardo 0fe99ee5b1 perf: add timeout and watch-mode cache extension to all data files
Introduce shared cachedFetch helper (lib/data-fetch.js) wrapping
EleventyFetch with two protections:

- 10-second hard timeout via AbortController on every network request,
  preventing slow or unresponsive APIs from hanging the build
- 4-hour cache TTL in watch/serve mode (vs 5-15 min originals), so
  incremental rebuilds serve from disk cache instead of re-fetching
  APIs every time a markdown file changes

All 13 network _data files updated to use cachedFetch. Production
builds keep original short TTLs for fresh data.

Targets the "Data File" benchmark (12,169ms / 32% of incremental
rebuild) — the largest remaining bottleneck after filter memoization.

Confab-Link: http://localhost:8080/sessions/0b241cd6-aff2-4fec-853c-2b5a61e61946
2026-03-10 17:11:24 +01:00

33 lines
941 B
JavaScript

/**
* GitHub Starred Repos Metadata
* Fetches the starred API response (cached 15min) to extract totalCount.
* Only totalCount is passed to Eleventy's data cascade — the full star
* list is discarded after parsing, keeping build memory low.
* The starred page fetches all data client-side via Alpine.js.
*/
import { cachedFetch } from "../lib/data-fetch.js";
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
export default async function () {
try {
const url = `${INDIEKIT_URL}/githubapi/api/starred/all`;
const response = await cachedFetch(url, {
duration: "15m",
type: "json",
});
return {
totalCount: response.totalCount || 0,
buildDate: new Date().toISOString(),
};
} catch (error) {
console.log(`[githubStarred] Could not fetch starred count: ${error.message}`);
return {
totalCount: 0,
buildDate: new Date().toISOString(),
};
}
}