Optimized posts_meta table join when meta columns are not requested (#11300)

no issue

- This change speeds up qery execution ommiting a join with posts_meta
table when there is no need to fetch meta columns
This commit is contained in:
Naz Gargol 2020-01-06 15:38:40 +01:00 committed by GitHub
parent 11d1acb475
commit c701293514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -803,7 +803,14 @@ Post = ghostBookshelf.Model.extend({
if (['edit', 'add', 'destroy'].indexOf(methodName) !== -1) {
options.withRelated = _.union(['authors', 'tags'], options.withRelated || []);
}
options.withRelated = _.union(['posts_meta'], 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
// optimization is needed to be able to perform .findAll on large SQLite datasets
if (!options.columns || (options.columns && _.intersection(META_ATTRIBUTES, options.columns).length)) {
options.withRelated = _.union(['posts_meta'], options.withRelated || []);
}
return options;
},