mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Deferred heavy permittedAttributes
call unless needed
- this code is on the hotpath for the URL service and has shown to be slow for sites with a lot of posts - this is due to the overhead of the lodash functions we use here - we can take advantage of how JS executes if-statements and move the variable into the if-statement, which lazy evaluates it (for the URL service, this branch is not hit, so it's a big win) - this cuts about 2% from CPU time
This commit is contained in:
parent
dd68fca968
commit
7bd70a3ab2
1 changed files with 5 additions and 3 deletions
|
@ -1290,11 +1290,13 @@ Post = ghostBookshelf.Model.extend({
|
||||||
options.withRelated = _.union(['authors', 'tags', 'post_revisions', 'post_revisions.author'], options.withRelated || []);
|
options.withRelated = _.union(['authors', 'tags', 'post_revisions', 'post_revisions.author'], options.withRelated || []);
|
||||||
}
|
}
|
||||||
|
|
||||||
const META_ATTRIBUTES = _.without(ghostBookshelf.model('PostsMeta').prototype.permittedAttributes(), 'id', 'post_id');
|
|
||||||
|
|
||||||
// NOTE: only include post_meta relation when requested in 'columns' or by default
|
// NOTE: only include post_meta relation when requested in 'columns' or by default
|
||||||
// optimization is needed to be able to perform .findAll on large SQLite datasets
|
// optimization is needed to be able to perform .findAll on large SQLite datasets
|
||||||
if (!options.columns || (options.columns && _.intersection(META_ATTRIBUTES, options.columns).length)) {
|
if (!options.columns
|
||||||
|
|| (
|
||||||
|
options.columns
|
||||||
|
&& _.intersection(_.without(ghostBookshelf.model('PostsMeta').prototype.permittedAttributes(), 'id', 'post_id'), options.columns).length)
|
||||||
|
) {
|
||||||
options.withRelated = _.union(['posts_meta'], options.withRelated || []);
|
options.withRelated = _.union(['posts_meta'], options.withRelated || []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue