From 32c9d07b90b2107e08689ff0e448bc92ffd341be Mon Sep 17 00:00:00 2001 From: Endi Date: Fri, 6 Dec 2019 12:17:41 +0700 Subject: [PATCH] perf(v2): improve dev build time by not overwriting file if possible (#2089) * perf(v2): improve sequential build time by not overwriting file if possible * minor improvement * docs --- packages/docusaurus-utils/src/index.ts | 14 +++++++++++++- website/docs/markdown-features.mdx | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 2b2b31b02a..131fd073b8 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -27,7 +27,19 @@ export async function generate( return; } - const lastHash = fileHash.get(filepath); + let lastHash = fileHash.get(filepath); + + // If file already exist but its not in runtime cache hash yet, + // we try to calculate the content hash and then compare + // This is to avoid unnecessary overwrite and we can reuse old file + if (!lastHash && fs.existsSync(filepath)) { + const lastContent = await fs.readFile(filepath, 'utf8'); + lastHash = createHash('md5') + .update(lastContent) + .digest('hex'); + fileHash.set(filepath, lastHash); + } + const currentHash = createHash('md5') .update(content) .digest('hex'); diff --git a/website/docs/markdown-features.mdx b/website/docs/markdown-features.mdx index b8ac1906f4..d89ff5ddb6 100644 --- a/website/docs/markdown-features.mdx +++ b/website/docs/markdown-features.mdx @@ -183,6 +183,7 @@ For example, if you are in `doc2.md` and you want to reference `doc1.md` and `fo ```md I am referencing a [document](doc1.md). Reference to another [document in a folder](folder/doc3.md) +[Relative document](../doc2.md) referencing works as well. ``` One benefit of this approach is that the links to external files will still work if you are viewing the file on GitHub.