Skip to content

Commit becf642

Browse files
committed
remove mdx caching
1 parent 50efd4d commit becf642

File tree

1 file changed

+0
-63
lines changed

1 file changed

+0
-63
lines changed

src/mdx.ts

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@ import matter from 'gray-matter';
55
import {s} from 'hastscript';
66
import yaml from 'js-yaml';
77
import {bundleMDX} from 'mdx-bundler';
8-
import {createReadStream, createWriteStream, mkdirSync} from 'node:fs';
98
import {access, opendir, readFile} from 'node:fs/promises';
109
import path from 'node:path';
11-
// @ts-expect-error ts(2305) -- For some reason "compose" is not recognized in the types
12-
import {compose, Readable} from 'node:stream';
13-
import {json} from 'node:stream/consumers';
14-
import {pipeline} from 'node:stream/promises';
15-
import {
16-
constants as zlibConstants,
17-
createBrotliCompress,
18-
createBrotliDecompress,
19-
} from 'node:zlib';
2010
import {limitFunction} from 'p-limit';
2111
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
2212
import rehypePresetMinify from 'rehype-preset-minify';
@@ -60,33 +50,6 @@ const root = process.cwd();
6050
// Functions which looks like AWS Lambda and we get `EMFILE` errors when trying to open
6151
// so many files at once.
6252
const FILE_CONCURRENCY_LIMIT = 200;
63-
const CACHE_COMPRESS_LEVEL = 4;
64-
const CACHE_DIR = path.join(root, '.next', 'cache', 'mdx-bundler');
65-
mkdirSync(CACHE_DIR, {recursive: true});
66-
67-
const md5 = (data: BinaryLike) => createHash('md5').update(data).digest('hex');
68-
69-
async function readCacheFile<T>(file: string): Promise<T> {
70-
const reader = createReadStream(file);
71-
const decompressor = createBrotliDecompress();
72-
73-
return (await json(compose(reader, decompressor))) as T;
74-
}
75-
76-
async function writeCacheFile(file: string, data: string) {
77-
await pipeline(
78-
Readable.from(data),
79-
createBrotliCompress({
80-
chunkSize: 32 * 1024,
81-
params: {
82-
[zlibConstants.BROTLI_PARAM_MODE]: zlibConstants.BROTLI_MODE_TEXT,
83-
[zlibConstants.BROTLI_PARAM_QUALITY]: CACHE_COMPRESS_LEVEL,
84-
[zlibConstants.BROTLI_PARAM_SIZE_HINT]: data.length,
85-
},
86-
}),
87-
createWriteStream(file)
88-
);
89-
}
9053

9154
function formatSlug(slug: string) {
9255
return slug.replace(/\.(mdx|md)/, '');
@@ -523,25 +486,6 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
523486
);
524487
}
525488

526-
let cacheKey: string | null = null;
527-
let cacheFile: string | null = null;
528-
529-
if (process.env.CI === '1') {
530-
cacheKey = md5(source);
531-
cacheFile = path.join(CACHE_DIR, cacheKey);
532-
533-
try {
534-
const cached = await readCacheFile<SlugFile>(cacheFile);
535-
return cached;
536-
} catch (err) {
537-
if (err.code !== 'ENOENT' && err.code !== 'ABORT_ERR') {
538-
// If cache is corrupted, ignore and proceed
539-
// eslint-disable-next-line no-console
540-
console.warn(`Failed to read MDX cache: ${cacheFile}`, err);
541-
}
542-
}
543-
}
544-
545489
process.env.ESBUILD_BINARY_PATH = path.join(
546490
root,
547491
'node_modules',
@@ -667,13 +611,6 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
667611
},
668612
};
669613

670-
if (cacheFile) {
671-
writeCacheFile(cacheFile, JSON.stringify(resultObj)).catch(e => {
672-
// eslint-disable-next-line no-console
673-
console.warn(`Failed to write MDX cache: ${cacheFile}`, e);
674-
});
675-
}
676-
677614
return resultObj;
678615
}
679616

0 commit comments

Comments
 (0)