From 5c8cc984d37ac2aaf20ac27fafe92cff34c78454 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 13 Aug 2020 01:32:39 -0700 Subject: [PATCH] refactor: slightly more efficient means of getting related resources for a node --- .../gatsby-source-swiftype/src/getRelatedResources.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/gatsby-source-swiftype/src/getRelatedResources.js b/plugins/gatsby-source-swiftype/src/getRelatedResources.js index f84424b0a..ebf59cb14 100644 --- a/plugins/gatsby-source-swiftype/src/getRelatedResources.js +++ b/plugins/gatsby-source-swiftype/src/getRelatedResources.js @@ -11,13 +11,16 @@ module.exports = async ({ node, siteUrl }, pluginOptions) => { getPath, } = pluginOptions; - const data = JSON.parse(fs.readFileSync(file)); - const params = getParams({ node }); const pathname = getPath({ node }); if (enabled) { - return search(siteUrl + pathname, params, { engineKey, pageLimit }); + return search(siteUrl + pathname, getParams({ node }), { + engineKey, + pageLimit, + }); } + const data = JSON.parse(fs.readFileSync(file)); + return data[pathname] || []; };