From 7ac0fdb23d3621f84692a13c3b50e675dd92bb94 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 17 Oct 2022 10:24:21 +0700 Subject: [PATCH] Fixed unnecessary requests with loading comment counts refs https://github.com/TryGhost/Team/issues/2082 - if a site has comments enabled but doesn't use the `comments_count` helper, the comments-count.min.js will still be loaded and it'll send a POST request to Ghost with an empty array of post IDs to fetch - this is unnecessary and we should avoid this extra request for pages that don't need to show comment counts - this commit prevents the comment-counts JS from sending the request if there are no post IDs to fetch --- .../core/frontend/src/comment-counts/js/comment-counts.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ghost/core/core/frontend/src/comment-counts/js/comment-counts.js b/ghost/core/core/frontend/src/comment-counts/js/comment-counts.js index c7045d30f6..725ece4642 100644 --- a/ghost/core/core/frontend/src/comment-counts/js/comment-counts.js +++ b/ghost/core/core/frontend/src/comment-counts/js/comment-counts.js @@ -63,6 +63,10 @@ const ids = Array.from(fetchingIds); fetchingIds.clear(); + if (!ids.length) { + return; + } + const rawRes = await fetch(api, { method: 'POST', headers: {