mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Removed DISTINCT from member labels association query (#12088)
no issue - bookshelf adds `DISTINCT` to any relation query that does not have an explicit `columns` statement - when measuring the impact of `DISTINCT` on the eager-loading association query when listing members using `{withRelated: 'labels'}`, it can be 2x slower with no index on the sort_order column or 4x slower with an index on sort_order
This commit is contained in:
parent
d9da01ea85
commit
577a934f53
1 changed files with 6 additions and 1 deletions
|
@ -25,7 +25,12 @@ const Member = ghostBookshelf.Model.extend({
|
||||||
labels: function labels() {
|
labels: function labels() {
|
||||||
return this.belongsToMany('Label', 'members_labels', 'member_id', 'label_id')
|
return this.belongsToMany('Label', 'members_labels', 'member_id', 'label_id')
|
||||||
.withPivot('sort_order')
|
.withPivot('sort_order')
|
||||||
.query('orderBy', 'sort_order', 'ASC');
|
.query('orderBy', 'sort_order', 'ASC')
|
||||||
|
.query((qb) => {
|
||||||
|
// avoids bookshelf adding a `DISTINCT` to the query
|
||||||
|
// we know the result set will already be unique and DISTINCT hurts query performance
|
||||||
|
qb.columns('labels.*');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
stripeCustomers() {
|
stripeCustomers() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue