From da68f1e1a60b2ec1b93ede7a75753002ca043be8 Mon Sep 17 00:00:00 2001 From: Matthias Rolke Date: Tue, 21 Nov 2023 22:48:41 +0100 Subject: [PATCH] fix: limit promise concurrency --- .github/workflows/default.yml | 2 ++ README.md | 2 ++ package.json | 1 + scripts/add-stars.js | 4 +++- scripts/get-commands.js | 4 +++- scripts/get-plugins.js | 4 +++- yarn.lock | 12 ++++++++++++ 7 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index ee57d7e..4a68d8b 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -19,6 +19,8 @@ jobs: - uses: actions/setup-node@v4 with: node-version-file: .node-version + - name: Install dependencies + run: yarn install - name: Build run: yarn build env: diff --git a/README.md b/README.md index b46bb83..abe51da 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ ## Development ``` +yarn install export GITHUB_TOKEN=xxx +yarn build yarn develop ``` diff --git a/package.json b/package.json index c3f3c15..66fc57c 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "author": "Matthias Rolke ", "license": "MIT", "devDependencies": { + "p-limit": "5.0.0", "serve": "14.2.1" }, "scripts": { diff --git a/scripts/add-stars.js b/scripts/add-stars.js index 43ad2b3..dbc11d5 100755 --- a/scripts/add-stars.js +++ b/scripts/add-stars.js @@ -2,6 +2,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; +import pLimit from "p-limit"; function getGitHubSlug(repositoryUrl) { if (repositoryUrl === undefined) { @@ -42,8 +43,9 @@ async function addStarsToPackage(pkg) { } async function addStarsToPackages(packages) { + const limit = pLimit(10); const result = await Promise.all( - packages.map((pkg) => addStarsToPackage(pkg)) + packages.map((pkg) => limit(() => addStarsToPackage(pkg))) ); return result; } diff --git a/scripts/get-commands.js b/scripts/get-commands.js index a4944fa..2ee03d2 100755 --- a/scripts/get-commands.js +++ b/scripts/get-commands.js @@ -2,6 +2,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; +import pLimit from "p-limit"; async function getManifest(plugin) { let result; @@ -18,7 +19,8 @@ async function getManifest(plugin) { } async function getCommands(plugins) { - const promises = plugins.map((plugin) => getManifest(plugin)); + const limit = pLimit(50); + const promises = plugins.map((plugin) => limit(() => getManifest(plugin))); const manifests = await Promise.all(promises); const commands = manifests .map((manifest) => Object.values(manifest?.commands || {})) diff --git a/scripts/get-plugins.js b/scripts/get-plugins.js index dd8f5f4..bf6f526 100755 --- a/scripts/get-plugins.js +++ b/scripts/get-plugins.js @@ -2,6 +2,7 @@ import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; +import pLimit from "p-limit"; const additionalPackages = []; const ignoredPackages = []; @@ -25,7 +26,8 @@ async function getPackage(packageName) { } async function getPackages(packageNames) { - const promises = packageNames.map((p) => getPackage(p)); + const limit = pLimit(50); + const promises = packageNames.map((p) => limit(() => getPackage(p))); const packages = await Promise.all(promises); return packages; } diff --git a/yarn.lock b/yarn.lock index f83142c..d910964 100644 --- a/yarn.lock +++ b/yarn.lock @@ -377,6 +377,13 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +p-limit@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-5.0.0.tgz#6946d5b7140b649b7a33a027d89b4c625b3a5985" + integrity sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ== + dependencies: + yocto-queue "^1.0.0" + path-is-inside@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" @@ -591,3 +598,8 @@ wrap-ansi@^8.0.1: ansi-styles "^6.1.0" string-width "^5.0.1" strip-ansi "^7.0.1" + +yocto-queue@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" + integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==