0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Invalidated the new comments endpoint cache on add & edit

refs https://linear.app/tryghost/issue/ENG-676/

This is the meat of the change and actually causes the cache to be
invalidated on adds and edits to the comments endpoints.

It doesn't currently include the liked/unliked actions at the moment
as we don't have easy access to the post id from those endpoints.
This commit is contained in:
Fabien O'Carroll 2024-02-27 19:29:24 -05:00 committed by Fabien 'egg' O'Carroll
parent a291914fc4
commit 58dd79ccb4
2 changed files with 43 additions and 14 deletions

View file

@ -74,20 +74,28 @@ module.exports = class CommentsController {
async edit(frame) {
this.#checkMember(frame);
let result;
if (frame.data.comments[0].status === 'deleted') {
return await this.service.deleteComment(
result = await this.service.deleteComment(
frame.options.id,
frame?.options?.context?.member?.id,
frame.options
);
} else {
result = await this.service.editCommentContent(
frame.options.id,
frame?.options?.context?.member?.id,
frame.data.comments[0].html,
frame.options
);
}
return await this.service.editCommentContent(
frame.options.id,
frame?.options?.context?.member?.id,
frame.data.comments[0].html,
frame.options
);
const postId = result?.get('post_id');
if (postId) {
frame.setHeader('X-Cache-Invalidate', `/api/members/comments/post/${result.get('post_id')}/`);
}
return result;
}
/**
@ -97,21 +105,29 @@ module.exports = class CommentsController {
this.#checkMember(frame);
const data = frame.data.comments[0];
let result;
if (data.parent_id) {
return await this.service.replyToComment(
result = await this.service.replyToComment(
data.parent_id,
frame.options.context.member.id,
data.html,
frame.options
);
} else {
result = await this.service.commentOnPost(
data.post_id,
frame.options.context.member.id,
data.html,
frame.options
);
}
return await this.service.commentOnPost(
data.post_id,
frame.options.context.member.id,
data.html,
frame.options
);
const postId = result?.get('post_id');
if (postId) {
frame.setHeader('X-Cache-Invalidate', `/api/members/comments/post/${result.get('post_id')}/`);
}
return result;
}
async destroy() {

View file

@ -106,6 +106,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-powered-by": "Express",
}
`;
@ -146,6 +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-powered-by": "Express",
}
`;
@ -1878,6 +1880,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-powered-by": "Express",
}
`;
@ -1936,6 +1939,7 @@ Object {
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-cache-invalidate": "/api/members/comments/post/618ba1ffbe2896088840a6df/",
"x-powered-by": "Express",
}
`;
@ -2354,6 +2358,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-powered-by": "Express",
}
`;
@ -2394,6 +2399,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-powered-by": "Express",
}
`;
@ -2434,6 +2440,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-powered-by": "Express",
}
`;
@ -2474,6 +2481,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-powered-by": "Express",
}
`;
@ -2935,6 +2943,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-powered-by": "Express",
}
`;
@ -2975,6 +2984,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-powered-by": "Express",
}
`;
@ -3015,6 +3025,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-powered-by": "Express",
}
`;
@ -3691,6 +3702,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-powered-by": "Express",
}
`;
@ -3731,6 +3743,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-powered-by": "Express",
}
`;