mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03: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
@ -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…
Reference in New Issue
Block a user