Skip to content

Commit

Permalink
perf(processor/post): improve processing speed if `config.post_asset_…
Browse files Browse the repository at this point in the history
…folder` is enabled
  • Loading branch information
yoshinorin committed Apr 18, 2024
1 parent 90b107c commit a4e79d1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/plugins/processor/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { extname, join } from 'path';
import { stat, listDir } from 'hexo-fs';
import { slugize, Pattern, Permalink } from 'hexo-util';
import { magenta } from 'picocolors';
import { posix } from 'path';

Check failure on line 8 in lib/plugins/processor/post.ts

View workflow job for this annotation

GitHub Actions / linter

'path' import is duplicated
import type { _File } from '../../box';
import type Hexo from '../../hexo';
import type { Stats } from 'fs';
Expand Down Expand Up @@ -278,16 +279,18 @@ function processAsset(ctx: Hexo, file: _File) {
return;
}

// TODO: Better post searching
const post = Post.toArray().find(post => file.source.startsWith(post.asset_dir));
if (post != null && (post.published || ctx._showDrafts())) {
return PostAsset.save({
_id: id,
slug: file.source.substring(post.asset_dir.length),
post: post._id,
modified: file.type !== 'skip',
renderable: file.params.renderable
});
if (Post.length > 0) {
const assetDir = id.slice(0, id.lastIndexOf("/"));

Check failure on line 283 in lib/plugins/processor/post.ts

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
const post = Post.findOne(p => p.asset_dir.endsWith(posix.join(assetDir, "/")));

Check failure on line 284 in lib/plugins/processor/post.ts

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
if (post != null && (post.published || ctx._showDrafts())) {
return PostAsset.save({
_id: id,
slug: file.source.substring(post.asset_dir.length),
post: post._id,
modified: file.type !== 'skip',
renderable: file.params.renderable
});
}
}

if (doc) {
Expand Down

0 comments on commit a4e79d1

Please sign in to comment.