Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(v2): convert synchronous filewrite to asynchronous #2936

Merged
merged 3 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,9 @@ export default function pluginContentBlog(
`${feedType}.xml`,
);
const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1();
try {
fs.writeFileSync(feedPath, feedContent);
} catch (err) {
return fs.outputFile(feedPath, feedContent).catch((err) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi

What about using async/await here too. I think we should progressively update to async/await everywhere for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @slorber ,
I know about that. But this a Promise.all, and should return promise. I dont think async/await is suitable.

async/await is good syntax but not fit any case

If you still persist in it, i will update it.

Thanks for you review

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem with Promise.all and async/await?

We already have this in other places already

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like in packages/docusaurus-plugin-content-docs/src/index.ts:464

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, just think this too redundancy —— its unnecessary to write async/await.

But if that is a project rule, i will comply with it.

throw new Error(`Generating ${feedType} feed failed: ${err}`);
}
});
}),
);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import fs from 'fs';
import fs from 'fs-extra';
import path from 'path';
import {PluginOptions} from './types';
import createSitemap from './createSitemap';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function pluginSitemap(
// Write sitemap file.
const sitemapPath = path.join(outDir, 'sitemap.xml');
try {
fs.writeFileSync(sitemapPath, generatedSitemap);
await fs.outputFile(sitemapPath, generatedSitemap);
} catch (err) {
throw new Error(`Sitemap error: ${err}`);
}
Expand Down