From 08f6c4e46b1791d6e441dda3a4673452dfdd6304 Mon Sep 17 00:00:00 2001 From: Snow Date: Mon, 14 Oct 2019 12:06:25 +1100 Subject: [PATCH] Set page[limit] to the number of related resources being requested. --- lib/postProcessing/include.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/postProcessing/include.js b/lib/postProcessing/include.js index 066279b9..70b81bcd 100644 --- a/lib/postProcessing/include.js +++ b/lib/postProcessing/include.js @@ -154,6 +154,7 @@ includePP._fillIncludeTree = (includeTree, request, callback) => { Object.keys(map.primary).forEach(relation => { let ids = _.uniq(map.primary[relation]) + const limit = ids.length const parts = relation.split('~~') const urlJoiner = '&filter[id]=' ids = urlJoiner + ids.join(urlJoiner) @@ -161,13 +162,14 @@ includePP._fillIncludeTree = (includeTree, request, callback) => { ids += `&${includeTree[parts[1]]._filter.join('&')}` } resourcesToFetch.push({ - url: `${jsonApi._apiConfig.base + parts[0]}/?${ids}`, + url: `${jsonApi._apiConfig.base + parts[0]}/?${ids}&page[limit]=${limit}`, as: relation }) }) Object.keys(map.foreign).forEach(relation => { let ids = _.uniq(map.foreign[relation]) + const limit = ids.length const parts = relation.split('~~') const urlJoiner = `&filter[${parts[0]}]=` ids = urlJoiner + ids.join(urlJoiner) @@ -175,7 +177,7 @@ includePP._fillIncludeTree = (includeTree, request, callback) => { ids += `&${includeTree[parts[2]]._filter.join('&')}` } resourcesToFetch.push({ - url: `${jsonApi._apiConfig.base + parts[1]}/?${ids}`, + url: `${jsonApi._apiConfig.base + parts[1]}/?${ids}&page[limit]=${limit}`, as: relation }) })