From 8e1f5529c7136922d547484702187210685ee44a Mon Sep 17 00:00:00 2001 From: Steve Larson <9larsons@gmail.com> Date: Tue, 20 Aug 2024 14:04:35 -0500 Subject: [PATCH] Fixed value destructuring for null values (#20803) ref 4267ff9 Found while testing other code. Appears to fail destructuring which prevents the job from running. --- .../core/server/services/email-analytics/lib/queries.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ghost/core/core/server/services/email-analytics/lib/queries.js b/ghost/core/core/server/services/email-analytics/lib/queries.js index f9b619828c..3063135d01 100644 --- a/ghost/core/core/server/services/email-analytics/lib/queries.js +++ b/ghost/core/core/server/services/email-analytics/lib/queries.js @@ -20,10 +20,10 @@ module.exports = { const startDate = new Date(); // separate queries is much faster than using max/greatest (with coalesce to handle nulls) across columns - let {maxOpenedAt} = events.includes('opened') ? await db.knex('email_recipients').select(db.knex.raw('MAX(opened_at) as maxOpenedAt')).first() : null; - let {maxDeliveredAt} = events.includes('delivered') ? await db.knex('email_recipients').select(db.knex.raw('MAX(delivered_at) as maxDeliveredAt')).first() : null; - let {maxFailedAt} = events.includes('failed') ? await db.knex('email_recipients').select(db.knex.raw('MAX(failed_at) as maxFailedAt')).first() : null; - + let maxOpenedAt = events.includes('opened') ? await db.knex('email_recipients').select(db.knex.raw('MAX(opened_at) as maxOpenedAt')).first().maxOpenedAt : null; + let maxDeliveredAt = events.includes('delivered') ? await db.knex('email_recipients').select(db.knex.raw('MAX(delivered_at) as maxDeliveredAt')).first().maxDeliveredAt : null; + let maxFailedAt = events.includes('failed') ? await db.knex('email_recipients').select(db.knex.raw('MAX(failed_at) as maxFailedAt')).first().maxFailedAt : null; + if (maxOpenedAt && !(maxOpenedAt instanceof Date)) { // SQLite returns a string instead of a Date maxOpenedAt = new Date(maxOpenedAt);