Skip to content

Commit

Permalink
feat(api): iterate sequentially
Browse files Browse the repository at this point in the history
Promise.all utilise toutes les connections à la base de données, ce qui
créé des ralentissements pour les autres requêtes.

Faire les requêtes de manières séquentielle permettra d'utiliser une
unique connection, ce qui aura pour conséquence de plus ralentir nos
utilisateurs
  • Loading branch information
VincentHardouin authored Nov 28, 2024
1 parent 3e4a7f8 commit 7b6b7cb
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions api/src/prescription/campaign/domain/usecases/create-campaigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ const createCampaigns = async function ({
userRepository,
organizationRepository,
}) {
const enrichedCampaignsData = await Promise.all(
campaignsToCreate.map(async (campaign) => {
await _checkIfOwnerIsExistingUser(userRepository, campaign.ownerId);
await _checkIfOrganizationExists(organizationRepository, campaign.organizationId);
const enrichedCampaignsData = [];
for (const campaign of campaignsToCreate) {
await _checkIfOwnerIsExistingUser(userRepository, campaign.ownerId);
await _checkIfOrganizationExists(organizationRepository, campaign.organizationId);

const generatedCampaignCode = await codeGenerator.generate(campaignAdministrationRepository);
const campaignCreator = await campaignCreatorRepository.get(campaign.organizationId);

return campaignCreator.createCampaign({
...campaign,
type: CampaignTypes.ASSESSMENT,
code: generatedCampaignCode,
});
}),
);
const generatedCampaignCode = await codeGenerator.generate(campaignAdministrationRepository);
const campaignCreator = await campaignCreatorRepository.get(campaign.organizationId);

const campaignToCreate = await campaignCreator.createCampaign({
...campaign,
type: CampaignTypes.ASSESSMENT,
code: generatedCampaignCode,
});
enrichedCampaignsData.push(campaignToCreate);
}
return campaignAdministrationRepository.save(enrichedCampaignsData);
};

Expand Down

0 comments on commit 7b6b7cb

Please sign in to comment.