From 7c57ffd6a68abd879b553343ecde3ebd3cdb8cdc Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 4 Dec 2020 13:12:14 +0000 Subject: [PATCH] Fixed posts without open rate being ordered in reverse refs https://github.com/TryGhost/Ghost/issues/12420 - adds additional sorting by post creation date so that posts below those with an open rate appear in a more useful order --- core/server/models/post.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index e5c4b57f11..f6fb662e7f 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -109,8 +109,11 @@ Post = ghostBookshelf.Model.extend({ // *1.0 is needed on one of the columns to prevent sqlite from // performing integer division rounding and always giving 0. // Order by emails.track_opens desc first so we always tracked emails - // before untracked emails in the posts list - orderByRaw: `emails.track_opens desc, emails.opened_count * 1.0 / emails.email_count * 100 ${direction}`, + // before untracked emails in the posts list. + orderByRaw: ` + emails.track_opens desc, + emails.opened_count * 1.0 / emails.email_count * 100 ${direction}, + posts.created_at desc`, eagerLoad: 'email.open_rate' }; }