From 4c10ae31d866931cc128b5101e9ba5e821b40d4e Mon Sep 17 00:00:00 2001 From: Lucie <25330882+lihbr@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:34:02 +0200 Subject: [PATCH] fix(manager): screenshot upload concurrency limit (DT-1532) (#1191) Co-authored-by: lihbr --- .../src/managers/screenshots/ScreenshotsManager.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts index 3288bd097a..25f222eaa1 100644 --- a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts +++ b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts @@ -1,5 +1,6 @@ import * as t from "io-ts"; import { fileTypeFromBuffer } from "file-type"; +import pLimit from "p-limit"; import fetch, { FormData, Blob, Response } from "../../lib/fetch"; import { checkIsURLAccessible } from "../../lib/checkIsURLAccessible"; @@ -47,6 +48,8 @@ function assertBrowserContextInitialized( } } +const uploadScreenshotLimit = pLimit(10); + /** * Encodes a part of a Slice Simulator URL to ensure it can be added to a URL * safely. @@ -283,10 +286,13 @@ export class ScreenshotsManager extends BaseManager { formData.set("file", new Blob([args.data], { type: fileType?.mime })); - const res = await fetch(this._s3ACL.uploadEndpoint, { - method: "POST", - body: formData, - }); + const s3ACLEndpoint = this._s3ACL.uploadEndpoint; + const res = await uploadScreenshotLimit(() => + fetch(s3ACLEndpoint, { + method: "POST", + body: formData, + }), + ); if (res.ok) { const url = new URL(key, this._s3ACL.imgixEndpoint);