Optimising count query : Added option param to skip distinct from count query for members events API
Ref https://linear.app/tryghost/issue/SLO-193/optimise-count-query-skip-distinct-from-count-query-for-members-events The member events endpoint have many queries like:- select count(distinct members_subscribe_events.id) as aggregate from `members_subscribe_events` where `members_subscribe_events`.`created_at` < '2024-07-30 11:30:39' In these queries, distinct is not required as id is a primary key. Skipping distinct would improve the performance. This PR will changed the query to:- select count(*) as aggregate from `members_subscribe_events` where `members_subscribe_events`.`created_at` < '2024-07-30 11:30:39'
This commit is contained in:
parent
61641bc7c6
commit
bb33a84058
@ -151,6 +151,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'newsletter'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -193,6 +194,7 @@ module.exports = class EventRepository {
|
||||
'stripeSubscription.stripePrice.stripeProduct.product'
|
||||
],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -245,6 +247,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -277,6 +280,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -314,6 +318,7 @@ module.exports = class EventRepository {
|
||||
'tagAttribution'
|
||||
],
|
||||
filter: 'subscriptionCreatedEvent.id:null+custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -368,6 +373,7 @@ module.exports = class EventRepository {
|
||||
'tagAttribution'
|
||||
],
|
||||
filter: 'member_id:-null+custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -416,6 +422,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'post', 'parent'],
|
||||
filter: 'member_id:-null+custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -449,6 +456,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'link', 'link.post'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -537,6 +545,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'post'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -571,6 +580,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'email'],
|
||||
filter: filterStr,
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -613,6 +623,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'email'],
|
||||
filter: 'delivered_at:-null+custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -655,6 +666,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'email'],
|
||||
filter: 'opened_at:-null+custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -697,6 +709,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'email'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -730,6 +743,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member', 'email'],
|
||||
filter: 'failed_at:-null+custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
@ -772,6 +786,7 @@ module.exports = class EventRepository {
|
||||
...options,
|
||||
withRelated: ['member'],
|
||||
filter: 'custom:true',
|
||||
useBasicCount: true,
|
||||
mongoTransformer: chainTransformers(
|
||||
// First set the filter manually
|
||||
replaceCustomFilterTransformer(filter),
|
||||
|
Loading…
Reference in New Issue
Block a user