Skip to content

Commit

Permalink
Fetch integration data in parallel for update (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni authored Oct 7, 2024
1 parent ac2f3bd commit 6246542
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"linkedom": "^0.16.4",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-to-string": "^4.0.0",
"p-limit": "^6.1.0",
"puppeteer": "^21.6.0",
"slugify": "^1.6.6",
"tiny-glob": "^0.2.9",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions scripts/npm.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { format, subDays } from 'date-fns';
import pLimit from 'p-limit';

async function fetchJson(url) {
const res = await fetch(url);
const fetchLimit = pLimit(10);

if (!res.ok) {
console.error(`[${url}] ${res.status} ${res.statusText}`);
throw new Error();
}
function fetchJson(url) {
return fetchLimit(async () => {
const res = await fetch(url);

return await res.json();
if (!res.ok) {
console.error(`[${url}] ${res.status} ${res.statusText}`);
throw new Error();
}

return await res.json();
})
}

const API_BASE_URL = 'https://api.npmjs.org/';
Expand Down
8 changes: 4 additions & 4 deletions scripts/update-integrations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async function unsafeUpdateAllIntegrations() {
const deprecatedIntegrations = [];

// loop through all integrations already published to the catalog
for (const entry of entries) {
await Promise.all(entries.map(async entry => {
const { data } = matter.read(entry);
existingIntegrations.add(data.name);

Expand All @@ -144,14 +144,14 @@ async function unsafeUpdateAllIntegrations() {
${frontmatter}---\n`,
);
}
}
}));

// find new integrations that haven't been published yet
const newIntegrations = Array.from(searchResults.keys()).filter(
(pkg) => !existingIntegrations.has(pkg),
);

for (const entry of newIntegrations) {
await Promise.all(newIntegrations.map(async (entry) => {
const details = await fetchWithOverrides(entry);

const frontmatter = yaml.stringify(details);
Expand All @@ -167,7 +167,7 @@ ${frontmatter}---\n`,
`---
${frontmatter}---\n`,
);
}
}));

updateLastModified();

Expand Down

0 comments on commit 6246542

Please sign in to comment.