diff --git a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20231206_163000.java b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20231206_163000.java index c65233e14bf0..16a87fa13065 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20231206_163000.java +++ b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20231206_163000.java @@ -1,5 +1,6 @@ package de.tum.in.www1.artemis.config.migration.entries; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -11,9 +12,8 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import com.google.common.collect.Lists; - import de.tum.in.www1.artemis.config.migration.MigrationEntry; +import de.tum.in.www1.artemis.domain.ProgrammingExercise; import de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage; import de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository; @@ -64,33 +64,27 @@ public void execute() { log.info("Migrating {} programming exercises. This might take a while.", exercisesToMigrate.size()); ExecutorService executorService = Executors.newFixedThreadPool(THREADS); - - var chunks = Lists.partition(exercisesToMigrate, BATCH_SIZE); - - for (var chunk : chunks) { - CompletableFuture[] allFutures = new CompletableFuture[Math.min(THREADS, chunk.size())]; - - for (int i = 0; i < chunk.size(); i++) { - var exercise = chunk.get(i); - allFutures[i] = CompletableFuture.runAsync(() -> { - boolean checkoutSolutionRepository = false; - try { - checkoutSolutionRepository = ciMigrationService.get().hasSolutionRepository(exercise.getTemplateBuildPlanId()); - } - catch (Exception e) { - log.error("Error while checking if exercise {} needs to check out solution repository in build plan, setting checkoutSolutionRepository to false", - exercise.getId(), e); - } - exercise.setCheckoutSolutionRepository(checkoutSolutionRepository); - log.debug("Migrated exercise {}", exercise.getId()); - programmingExerciseRepository.save(exercise); - }, executorService); - } - - // Wait until all currently loaded exercises are migrated to avoid loading too many exercises at the same time. - CompletableFuture.allOf(allFutures).join(); + List> allFutures = new ArrayList<>(); + + for (ProgrammingExercise exercise : exercisesToMigrate) { + allFutures.add(CompletableFuture.runAsync(() -> { + boolean checkoutSolutionRepository = false; + try { + checkoutSolutionRepository = ciMigrationService.get().hasSolutionRepository(exercise.getTemplateBuildPlanId()); + } + catch (Exception e) { + log.error("Error while checking if exercise {} needs to check out solution repository in build plan, setting checkoutSolutionRepository to false", + exercise.getId(), e); + } + exercise.setCheckoutSolutionRepository(checkoutSolutionRepository); + log.debug("Migrated exercise {}", exercise.getId()); + programmingExerciseRepository.save(exercise); + }, executorService)); } + // Wait until all currently loaded exercises are migrated to avoid loading too many exercises at the same time. + CompletableFuture.allOf(allFutures.toArray(new CompletableFuture[] {})).join(); + executorService.shutdown(); }