Skip to content

Commit

Permalink
Improve memory performance of redirects
Browse files Browse the repository at this point in the history
For sites that have a large number of redirects, the existing
implementation will throw a `RangeError: Maximum call stack size
exceeded` error, as all the redirect jobs are first built into memory,
then spread out into the uploadQueue. This change tweaks the flow to
push the redirect jobs into the queue using a forEach loop instead,
which doesn't trigger this same error with a large number of redirects.
  • Loading branch information
mattrigg9 committed Dec 6, 2022
1 parent 9365136 commit 1ebe614
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gatsby-plugin-s3/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ export const deploy = async ({ yes, bucket, userAgent }: DeployArguments = {}) =
});

const base = config.protocol && config.hostname ? `${config.protocol}://${config.hostname}` : null;
uploadQueue.push(
...redirectObjects.map(redirect =>
redirectObjects.forEach(redirect =>
uploadQueue.push(
asyncify(async () => {
const { fromPath, toPath: redirectPath } = redirect;
const redirectLocation = base ? resolveUrl(base, redirectPath) : redirectPath;
Expand Down

0 comments on commit 1ebe614

Please sign in to comment.