Skip to content

Commit

Permalink
fix: scenario features specification piece importer (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
aciddaute authored May 17, 2022
1 parent 9e41dbf commit a201da8
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isDefined, readableToBuffer } from '@marxan/utils';
import { Injectable, Logger } from '@nestjs/common';
import { InjectEntityManager } from '@nestjs/typeorm';
import { isLeft } from 'fp-ts/lib/Either';
import { chunk } from 'lodash';
import { EntityManager, In } from 'typeorm';
import { v4 } from 'uuid';
import {
Expand Down Expand Up @@ -390,16 +391,17 @@ export class ScenarioFeaturesSpecificationPieceImporter
const scenarioFeaturesDataRepo = em.getRepository(ScenarioFeaturesData);

await Promise.all(
Object.keys(featureIdsBySpecificationId).map(
async (specificationId) => {
const featureIds = featureIdsBySpecificationId[specificationId];
Object.keys(featureIdsBySpecificationId).flatMap((specificationId) => {
const featureIds = featureIdsBySpecificationId[specificationId];
const chunkSize = 1000;

return scenarioFeaturesDataRepo.update(
{ scenarioId, featureId: In(featureIds) },
return chunk(featureIds, chunkSize).map((chunkFeatureIds) =>
scenarioFeaturesDataRepo.update(
{ scenarioId, featureId: In(chunkFeatureIds) },
{ specificationId },
);
},
),
),
);
}),
);
});

Expand Down

0 comments on commit a201da8

Please sign in to comment.