From 35f430a8ec1045b11ebd11b57a22d0a54caad6af Mon Sep 17 00:00:00 2001 From: Nitin Jadhav <3931042+nitinja@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:48:15 -0600 Subject: [PATCH] Update packages/spacecat-shared-rum-api-client/src/functions/404-internal-links.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced reduce with map function, which is more appropriate here Co-authored-by: Ekrem Doğan --- .../src/functions/404-internal-links.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/spacecat-shared-rum-api-client/src/functions/404-internal-links.js b/packages/spacecat-shared-rum-api-client/src/functions/404-internal-links.js index 53c7e316..b0c326f4 100644 --- a/packages/spacecat-shared-rum-api-client/src/functions/404-internal-links.js +++ b/packages/spacecat-shared-rum-api-client/src/functions/404-internal-links.js @@ -45,21 +45,15 @@ function handler(bundles) { // counts pageviews per each group dataChunks.addSeries('views', series.pageViews); - const brokenInternalLinksViews = dataChunks.facets.uniqueUrlCombinations - .reduce((acc, facet) => { - const urlCombination = facet.value; - - acc[urlCombination] = acc[urlCombination] || {}; - - acc[urlCombination].views = facet.metrics.views.sum; + return dataChunks.facets.uniqueUrlCombinations.map((facet) => { const [urlTo, urlFrom] = facet.value.split(DELIMITER); - acc[urlCombination].url_to = urlTo; - acc[urlCombination].url_from = urlFrom; - - return acc; - }, {}); - - return Object.values(brokenInternalLinksViews); + + return { + views: facet.metrics.views.sum, + url_to: urlTo, + url_from: urlFrom, + } + }); } export default {