Skip to content

Instantly share code, notes, and snippets.

@reneluria
Created May 26, 2025 12:44
Show Gist options
  • Select an option

  • Save reneluria/8cbbfbc001e542c77d6d5887fbafe5d3 to your computer and use it in GitHub Desktop.

Select an option

Save reneluria/8cbbfbc001e542c77d6d5887fbafe5d3 to your computer and use it in GitHub Desktop.
ghost post patch for mariadb
--- core/server/models/post.js.orig 2025-05-26 12:26:03.841883165 +0000
+++ core/server/models/post.js 2025-05-26 12:41:59.594432516 +0000
@@ -1564,21 +1564,29 @@
* Combination of sigups and paid conversions, but unique per member
*/
conversions(modelOrCollection) {
- modelOrCollection.query('columns', 'posts.*', (qb) => {
- qb.count('*')
- .from('k')
- .with('k', (q) => {
- q.select('member_id')
- .from('members_subscription_created_events')
- .whereRaw('posts.id = members_subscription_created_events.attribution_id')
- .union(function () {
- this.select('member_id')
- .from('members_created_events')
- .whereRaw('posts.id = members_created_events.attribution_id');
- });
- })
- .as('count__conversions');
+ modelOrCollection.query('columns', 'posts.*');
+
+ modelOrCollection.query((qb) => {
+ qb.leftJoin(
+ ghostBookshelf.knex.raw(`(
+ SELECT
+ COALESCE(COUNT(DISTINCT member_id), 0) AS count__conversions,
+ attribution_id as post_id
+ FROM (
+ SELECT member_id, attribution_id
+ FROM members_subscription_created_events
+ UNION ALL
+ SELECT member_id, attribution_id
+ FROM members_created_events
+ ) AS all_events
+ GROUP BY attribution_id
+ ) as conversions_sub`),
+ 'posts.id',
+ 'conversions_sub.post_id'
+ )
+ .select('conversions_sub.count__conversions');
});
+
},
clicks(modelOrCollection) {
modelOrCollection.query('columns', 'posts.*', (qb) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment