Skip to content

Commit 2d844df

Browse files
Fix metadata cache to support locale matching in fetchMetadataWithCache
1 parent 2e413f0 commit 2d844df

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

apps/nextjs-website/src/helpers/s3Metadata.helpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable functional/no-let */
22
/* eslint-disable functional/no-expression-statements */
33
import { s3DocsPath, staticContentsUrl } from '@/config';
4+
import { cons } from 'fp-ts/lib/ReadonlyNonEmptyArray';
45
import * as path from 'node:path';
56

67
export interface JsonMetadata {
@@ -224,16 +225,16 @@ async function fetchMetadataWithCache<T extends { readonly dirName: string }>(
224225
): Promise<MetadataCacheItem<T>> {
225226
const now = Date.now();
226227
const cacheResult = metadataCache.find((item) => {
227-
const categoryMatch =
228-
item.category === metadataCategory && item.locale === locale;
228+
const categoryMatch = item.category === metadataCategory;
229+
const localeMatch = item.locale === locale;
229230
const timeMatch = item.data && now - item.refreshTime < METADATA_CACHE_TTL;
230231
const dirNameMatch =
231232
!dirName ||
232233
(Array.isArray(item.data) &&
233234
item.data.length > 0 &&
234235
'dirName' in item.data[0] &&
235236
item.data.some((m: Record<string, unknown>) => m.dirName === dirName));
236-
return categoryMatch && timeMatch && dirNameMatch;
237+
return categoryMatch && localeMatch && timeMatch && dirNameMatch;
237238
}) as MetadataCacheItem<T> | undefined;
238239

239240
if (cacheResult) {

0 commit comments

Comments
 (0)