mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
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:
parent
11d1acb475
commit
c701293514
@ -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;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user