Skip to content

Commit

Permalink
fix(ingester): set pmap instead of promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Dec 8, 2023
1 parent 96aee3e commit 248870c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
40 changes: 19 additions & 21 deletions targets/ingester/src/articles/update-kali-articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ export const updateKaliArticles = async (): Promise<void> => {
const { agreements } = await loadAgreements();

let i = 0;
await Promise.all(
await pMap(
agreements,
async ({ idcc, kali_id }) => {
console.log(
`updateKaliData: ${++i}/${
agreements.length
} Updating agreement for IDCC ${idcc}`
);
const articles = await loadAgreementArticles(
kali_id,
idcc,
loadAgreement,
loadArticles
);
await updateAgreementArticles(idcc, articles);
},
{
concurrency: 10,
}
)
await pMap(
agreements,
async ({ idcc, kali_id }) => {
console.log(
`updateKaliData: ${++i}/${
agreements.length
} Updating agreement for IDCC ${idcc}`
);
const articles = await loadAgreementArticles(
kali_id,
idcc,
loadAgreement,
loadArticles
);
await updateAgreementArticles(idcc, articles);
},
{
concurrency: 10,
}
);
};
3 changes: 3 additions & 0 deletions targets/ingester/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,15 @@ async function main() {
}

if (packagesToUpdate.get("@socialgouv/legi-data")) {
console.log("update legi articles");
await updateLegiArticles();
}
if (packagesToUpdate.get("@socialgouv/kali-data")) {
console.log("update kali articles");
await updateKaliArticles();
}
if (packagesToUpdate.get("@socialgouv/contributions-data")) {
console.log("set contributions availability to true");
await setContributionsAvailabilityToTrue();
}
return ids;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetchDocumentContributions } from "./fetchContributions";
import { updateDocumentAvailabilityToTrue } from "./updateDocument";
import pMap from "p-map";

export async function setContributionsAvailabilityToTrue() {
// Nous allons récupérer les contributions de la table document
Expand All @@ -13,14 +14,14 @@ export async function setContributionsAvailabilityToTrue() {
(v) => v.slug
);

const promises = [];

// Pour chacune des nouvelles contributions nous allons les passer en is_available à true, car l'ingester les passe à false.
for (let i = 0; i < allNewContributionsBySlug.length; i++) {
promises.push(
updateDocumentAvailabilityToTrue(allNewContributionsBySlug[i])
);
}

await Promise.all(promises);
await pMap(
allNewContributionsBySlug,
(contrib) => {
return updateDocumentAvailabilityToTrue(contrib);
},
{
concurrency: 10,
}
);
}

0 comments on commit 248870c

Please sign in to comment.