mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Added /comments/:id/replies/ to X-Cache-Invalidate
refs https://linear.app/tryghost/issue/ENG-682/ This should allow us to bust both endpoints cache when write operations are made to comments.
This commit is contained in:
parent
c2f3ffaca7
commit
a489d5a3d8
3 changed files with 47 additions and 23 deletions
ghost/core
core/server/services/comments
test/e2e-api/members-comments
|
@ -90,9 +90,14 @@ module.exports = class CommentsController {
|
|||
);
|
||||
}
|
||||
|
||||
const postId = result?.get('post_id');
|
||||
if (postId) {
|
||||
frame.setHeader('X-Cache-Invalidate', `/api/members/comments/post/${postId}/`);
|
||||
if (result) {
|
||||
const postId = result.get('post_id');
|
||||
const parentId = result.get('parent_id');
|
||||
const pathsToInvalidate = [
|
||||
postId ? `/api/members/comments/post/${postId}/` : null,
|
||||
parentId ? `/api/members/comments/${parentId}/replies/` : null
|
||||
].filter(path => path !== null);
|
||||
frame.setHeader('X-Cache-Invalidate', pathsToInvalidate.join(', '));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -122,9 +127,14 @@ module.exports = class CommentsController {
|
|||
);
|
||||
}
|
||||
|
||||
const postId = result?.get('post_id');
|
||||
if (postId) {
|
||||
frame.setHeader('X-Cache-Invalidate', `/api/members/comments/post/${postId}/`);
|
||||
if (result) {
|
||||
const postId = result.get('post_id');
|
||||
const parentId = result.get('parent_id');
|
||||
const pathsToInvalidate = [
|
||||
postId ? `/api/members/comments/post/${postId}/` : null,
|
||||
parentId ? `/api/members/comments/${parentId}/replies/` : null
|
||||
].filter(path => path !== null);
|
||||
frame.setHeader('X-Cache-Invalidate', pathsToInvalidate.join(', '));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -160,9 +170,14 @@ module.exports = class CommentsController {
|
|||
|
||||
const comment = await this.service.getCommentByID(frame.options.id);
|
||||
|
||||
const postId = comment?.get('post_id');
|
||||
if (postId) {
|
||||
frame.setHeader('X-Cache-Invalidate', `/api/members/comments/post/${postId}/`);
|
||||
if (comment) {
|
||||
const postId = comment.get('post_id');
|
||||
const parentId = comment.get('parent_id');
|
||||
const pathsToInvalidate = [
|
||||
postId ? `/api/members/comments/post/${postId}/` : null,
|
||||
parentId ? `/api/members/comments/${parentId}/replies/` : null
|
||||
].filter(path => path !== null);
|
||||
frame.setHeader('X-Cache-Invalidate', pathsToInvalidate.join(', '));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -182,10 +197,16 @@ module.exports = class CommentsController {
|
|||
|
||||
const comment = await this.service.getCommentByID(frame.options.id);
|
||||
|
||||
const postId = comment?.get('post_id');
|
||||
if (postId) {
|
||||
frame.setHeader('X-Cache-Invalidate', `/api/members/comments/post/${postId}/`);
|
||||
if (comment) {
|
||||
const postId = comment.get('post_id');
|
||||
const parentId = comment.get('parent_id');
|
||||
const pathsToInvalidate = [
|
||||
postId ? `/api/members/comments/post/${postId}/` : null,
|
||||
parentId ? `/api/members/comments/${parentId}/replies/` : null
|
||||
].filter(path => path !== null);
|
||||
frame.setHeader('X-Cache-Invalidate', pathsToInvalidate.join(', '));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -2183,7 +2183,7 @@ Object {
|
|||
"access-control-allow-origin": "*",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -2449,7 +2449,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -2490,7 +2490,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -2531,7 +2531,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -2572,7 +2572,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": StringMatching /\\\\/api\\\\/members\\\\/comments\\\\/post\\\\/\\[0-9a-f\\]\\{24\\}\\\\/, \\\\/api\\\\/members\\\\/comments\\\\/\\[0-9a-f\\]\\{24\\}\\\\/replies\\\\//,
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -3034,7 +3034,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -3075,7 +3075,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -3116,7 +3116,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
@ -3834,7 +3834,7 @@ Object {
|
|||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/comments\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Encoding",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
|
||||
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/, /api/members/comments/6195c6a1e792de832cd08144/replies/",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -381,7 +381,10 @@ describe('Comments API', function () {
|
|||
.expectStatus(201)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag,
|
||||
location: anyLocationFor('comments')
|
||||
location: anyLocationFor('comments'),
|
||||
'x-cache-invalidate': matchers.stringMatching(
|
||||
new RegExp('/api/members/comments/post/[0-9a-f]{24}/, /api/members/comments/[0-9a-f]{24}/replies/')
|
||||
)
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
comments: [commentMatcher]
|
||||
|
|
Loading…
Add table
Reference in a new issue