From 507d8b32dbecd9bc5e9457e5837f65248a03dfde Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 12 Mar 2019 18:35:54 +0000 Subject: [PATCH] Fixed previews not reflecting changes to scheduled posts on Ghost(Pro) (#10601) closes https://github.com/TryGhost/Ghost/issues/10600 - modifies conditions for when to send a cache invalidation header for preview URLs to include changes to scheduled posts --- core/server/api/v2/pages.js | 11 ++++++++--- core/server/api/v2/posts.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/server/api/v2/pages.js b/core/server/api/v2/pages.js index ac19536a4c..a5fb776909 100644 --- a/core/server/api/v2/pages.js +++ b/core/server/api/v2/pages.js @@ -132,10 +132,15 @@ module.exports = { query(frame) { return models.Post.edit(frame.data.pages[0], frame.options) .then((model) => { - if (model.get('status') === 'published' && model.wasChanged() || - model.get('status') === 'draft' && model.previous('status') === 'published') { + if ( + model.get('status') === 'published' && model.wasChanged() || + model.get('status') === 'draft' && model.previous('status') === 'published' + ) { this.headers.cacheInvalidate = true; - } else if (model.get('status') === 'draft' && model.previous('status') !== 'published') { + } else if ( + model.get('status') === 'draft' && model.previous('status') !== 'published' || + model.get('status') === 'scheduled' && model.wasChanged() + ) { this.headers.cacheInvalidate = { value: urlService.utils.urlFor({ relativeUrl: urlService.utils.urlJoin('/p', model.get('uuid'), '/') diff --git a/core/server/api/v2/posts.js b/core/server/api/v2/posts.js index 64035361ee..09f244fbfd 100644 --- a/core/server/api/v2/posts.js +++ b/core/server/api/v2/posts.js @@ -136,10 +136,15 @@ module.exports = { query(frame) { return models.Post.edit(frame.data.posts[0], frame.options) .then((model) => { - if (model.get('status') === 'published' && model.wasChanged() || - model.get('status') === 'draft' && model.previous('status') === 'published') { + if ( + model.get('status') === 'published' && model.wasChanged() || + model.get('status') === 'draft' && model.previous('status') === 'published' + ) { this.headers.cacheInvalidate = true; - } else if (model.get('status') === 'draft' && model.previous('status') !== 'published') { + } else if ( + model.get('status') === 'draft' && model.previous('status') !== 'published' || + model.get('status') === 'scheduled' && model.wasChanged() + ) { this.headers.cacheInvalidate = { value: urlService.utils.urlFor({ relativeUrl: urlService.utils.urlJoin('/p', model.get('uuid'), '/')