Skip to content

Commit

Permalink
Updated prefetch strategy to first attempt search using POST - only u…
Browse files Browse the repository at this point in the history
…sing GET when POST results in an error
  • Loading branch information
c-schuler committed Nov 8, 2024
1 parent f4c8a15 commit 496ab1a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/retrieve-data-helpers/service-exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function prefetchDataPromises(state, baseUrl, prefetch) {
for (let i = 0; i < prefetchKeys.length; i += 1) {
const key = prefetchKeys[i];
const prefetchValue = prefetchRequests[key];
if (prefetchValue.length > 2000) {
let usePost = false;
if (i === 0 || usePost) {
const resource = prefetchValue.split('?')[0]; // TODO: investigate edge cases
const params = new URLSearchParams(prefetchValue.split('?')[1]);
axios({
Expand All @@ -114,17 +115,19 @@ function prefetchDataPromises(state, baseUrl, prefetch) {
if (result.data && Object.keys(result.data).length) {
resultingPrefetch[key] = result.data;
}
usePost = true;
resolveWhenDone();
})
.catch((err) => {
// Since prefetch is best-effort, don't throw; just log it and continue
console.log(
`Unable to prefetch data for ${baseUrl}/${prefetchValue}`,
`Unable to prefetch data using POST for ${baseUrl}/${prefetchValue}`,
err,
);
resolveWhenDone();
});
} else {
}
if (!usePost) {
axios({
method: 'get',
url: `${baseUrl}/${prefetchValue}`,
Expand Down

0 comments on commit 496ab1a

Please sign in to comment.