File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 1
1
import pMemoize from 'p-memoize' ;
2
2
3
+ /**
4
+ * We wrap 'use cache' calls in a p-memoize function to avoid
5
+ * executing the function multiple times when doing concurrent calls.
6
+ *
7
+ * Hopefully one day this can be done directly by 'use cache'.
8
+ */
3
9
export function memoize < F extends ( ...args : any [ ] ) => any > ( f : F ) : F {
4
10
return pMemoize ( f , {
5
11
cacheKey : ( args ) => {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type {
6
6
OpenAPISchemasBlock ,
7
7
ResolveOpenAPIBlockArgs ,
8
8
} from '@/lib/openapi/types' ;
9
+ import { memoize } from '@v2/lib/data/memoize' ;
9
10
import { assert } from 'ts-essentials' ;
10
11
import { resolveContentRef } from '../references' ;
11
12
import { isV2 } from '../v2' ;
@@ -65,15 +66,15 @@ const fetchFilesystemV1 = cache({
65
66
} ,
66
67
} ) ;
67
68
68
- async function fetchFilesystemV2 ( url : string ) {
69
+ const fetchFilesystemV2 = memoize ( async function fetchFilesystemV2 ( url : string ) {
69
70
'use cache' ;
70
71
71
72
// TODO: add cache lifetime once we can use next.js 15 code here
72
73
73
74
const response = await fetchFilesystemUncached ( url ) ;
74
75
75
76
return response ;
76
- }
77
+ } ) ;
77
78
78
79
async function fetchFilesystemUncached (
79
80
url : string ,
You can’t perform that action at this time.
0 commit comments