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

WIP: perf(router): avoid calling set when the generated data unmodified #5482

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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: 5 additions & 1 deletion lib/hexo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,11 @@ class Hexo extends EventEmitter {
const { data, layout } = generatorResult;

if (!layout) {
route.set(path, data);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Comment on lines +629 to +630
Copy link
Member

Choose a reason for hiding this comment

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

Always prefer // @ts-expect-error, do not use // @ts-ignore

if (data.modified == null || data.modified) {
route.set(path, data);
}
return path;
}

Expand Down
12 changes: 6 additions & 6 deletions test/scripts/hexo/hexo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,26 @@ describe('Hexo', () => {
hexo.extend.filter.unregister('before_generate', validateThemeConfig);
});

async function testWatch(path) {
const target = join(path, 'test.txt');
async function testWatch(path, fileName) {
const target = join(path, fileName);
const body = 'test';
const newBody = body + body;

loadAssetGenerator();

await writeFile(target, body);
await hexo.watch();
await checkStream(route.get('test.txt'), body); // Test for first generation
await checkStream(route.get(fileName), body); // Test for first generation
await writeFile(target, newBody); // Update the file
await Promise.delay(300);
await checkStream(route.get('test.txt'), newBody); // Check the new route
await checkStream(route.get(fileName), newBody); // Check the new route
hexo.unwatch(); // Stop watching
await unlink(target); // Delete the file
}

it('watch() - source', async () => await testWatch(hexo.source_dir));
it('watch() - source', async () => await testWatch(hexo.source_dir, 'source.test.watch.txt'));
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to use unique files for each test for watch. Because using the same files (test.txt) as other tests caused failures. Perhaps caused by caching or something similar, but I'm not sure.


it('watch() - theme', async () => await testWatch(join(hexo.theme_dir, 'source')));
it('watch() - theme', async () => await testWatch(join(hexo.theme_dir, 'source'), 'theme.test.watch.txt'));

it('watch() - merge theme config', () => {
const theme_config_1 = [
Expand Down
Loading