Skip to content

Commit 680c7c4

Browse files
authoredFeb 13, 2024··
feat: Cache api schema for build (#9126)
* feat: Cache api schema for build * Add no automatic caching because of 2mb limit
1 parent e4f521a commit 680c7c4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎src/build/resolveOpenAPI.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const SENTRY_API_SCHEMA_SHA = 'deea76e7205d4e1efb45f91796b9fc73499de226';
1414

1515
const activeEnv = process.env.GATSBY_ENV || process.env.NODE_ENV || 'development';
1616

17+
let cachedResonse: DeRefedOpenAPI | null = null;
18+
1719
async function resolveOpenAPI(): Promise<DeRefedOpenAPI> {
1820
if (activeEnv === 'development' && process.env.OPENAPI_LOCAL_PATH) {
1921
try {
@@ -27,10 +29,16 @@ async function resolveOpenAPI(): Promise<DeRefedOpenAPI> {
2729
);
2830
}
2931
}
32+
33+
if (cachedResonse) {
34+
return cachedResonse;
35+
}
3036
const response = await fetch(
31-
`https://raw.githubusercontent.com/getsentry/sentry-api-schema/${SENTRY_API_SCHEMA_SHA}/openapi-derefed.json`
37+
`https://raw.githubusercontent.com/getsentry/sentry-api-schema/${SENTRY_API_SCHEMA_SHA}/openapi-derefed.json`,
38+
{cache: 'no-store'}
3239
);
33-
return await response.json();
40+
cachedResonse = await response.json();
41+
return cachedResonse!;
3442
}
3543

3644
export type APIParameter = {

0 commit comments

Comments
 (0)
Please sign in to comment.