File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed
Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ async function populateR2BucketDirectory(directory: Directory): Promise<void> {
2828 await Promise . all ( promises ) ;
2929}
3030
31- function populateDirectoryCache ( directory : Directory ) : Array < Promise < unknown > > {
31+ async function populateDirectoryCache ( directory : Directory ) : Promise < void > {
3232 let hasIndexHtmlFile = false ;
3333 const cachedDirectory : ReadDirectoryResult = {
3434 subdirectories : Object . keys ( directory . subdirectories ) ,
@@ -58,7 +58,7 @@ function populateDirectoryCache(directory: Directory): Array<Promise<unknown>> {
5858 ...Object . values ( directory . subdirectories ) . map ( populateDirectoryCache ) ,
5959 ] ;
6060
61- return promises ;
61+ await Promise . all ( promises ) ;
6262}
6363
6464/**
@@ -77,7 +77,7 @@ export async function populateDirectoryCacheWithDevBucket(): Promise<void> {
7777 const devBucket = inject ( 'devBucket' ) ;
7878
7979 // Write it to KV
80- await Promise . all ( populateDirectoryCache ( devBucket ) ) ;
80+ await populateDirectoryCache ( devBucket ) ;
8181}
8282
8383declare module 'cloudflare:test' {
Original file line number Diff line number Diff line change @@ -98,8 +98,8 @@ export async function addVersionSymlinksToCachedDocsDirectory(
9898 subdirectory . startsWith ( 'v' ) || subdirectory . startsWith ( 'latest' )
9999 ) ;
100100
101- docsDirectory . subdirectories = Array . from (
102- new Set ( [ ... docsDirectory . subdirectories , ... versionDirectories ] )
101+ docsDirectory . subdirectories = makeArrayUnique (
102+ docsDirectory . subdirectories . concat ( versionDirectories )
103103 ) . sort ( ) ;
104104}
105105
@@ -243,3 +243,30 @@ export async function addSymlinksToDirectoryCache(
243243
244244 await addStaticFileSymlinksToCache ( client , cachedDirectories , latestVersion ) ;
245245}
246+
247+ /**
248+ * Make an array unique without needing to copy its contents or do things
249+ * more inefficiently
250+ *
251+ * @template {Array<unknown>} T
252+ *
253+ * @param {T } array
254+ * @returns {T }
255+ */
256+ function makeArrayUnique ( array ) {
257+ /**
258+ * @type {Record<T[number], boolean> }
259+ */
260+ const seen = { } ;
261+
262+ return array . filter ( value => {
263+ // eslint-disable-next-line no-prototype-builtins
264+ if ( seen . hasOwnProperty ( value ) ) {
265+ return false ;
266+ }
267+
268+ seen [ value ] = true ;
269+
270+ return true ;
271+ } ) ;
272+ }
You can’t perform that action at this time.
0 commit comments