From ed5737e77d267d224e38c3186484b60711224df6 Mon Sep 17 00:00:00 2001 From: Hanvp Date: Tue, 30 Jan 2024 23:01:32 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20Refactor/296=20ParallelStream=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zipdabang/server/converter/RecipeConverter.java | 6 +++--- .../server/service/serviceImpl/RecipeServiceImpl.java | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/zipdabang/server/converter/RecipeConverter.java b/src/main/java/zipdabang/server/converter/RecipeConverter.java index c60f4fb..3449456 100644 --- a/src/main/java/zipdabang/server/converter/RecipeConverter.java +++ b/src/main/java/zipdabang/server/converter/RecipeConverter.java @@ -747,7 +747,7 @@ public static TestRecipe toTestRecipe(RecipeRequestDto.CreateRecipeDto request, } public static List toTestRecipeCategory(List categoryIds, TestRecipe recipe) { - return categoryIds.stream() + return categoryIds.stream().parallel() .map(recipeCategoryId -> toTestRecipeCategoryMappingDto(recipeCategoryId, recipe)) .collect(Collectors.toList()); } @@ -760,7 +760,7 @@ private static TestRecipeCategoryMapping toTestRecipeCategoryMappingDto(Long cat } public static List toTestStep(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe, List stepImages) { - return request.getSteps().stream() + return request.getSteps().stream().parallel() .map(step-> { if (step.getDescription() == null) throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR); @@ -801,7 +801,7 @@ private static TestStep toTestStepDto(RecipeRequestDto.StepDto step, TestRecipe } public static List toTestIngredient(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe) { - return request.getIngredients().stream() + return request.getIngredients().stream().parallel() .map(ingredient -> toTestIngredientDto(ingredient, recipe)) .collect(Collectors.toList()); } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java index 26f6891..bf737aa 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java @@ -938,7 +938,7 @@ public TestRecipe getTestRecipe(Long recipeId) { return findRecipe; } - @Transactional(readOnly = false) + @Transactional @Override public Page testRecipeListByCategory(Long categoryId, Integer pageIndex, String order) { @@ -970,16 +970,17 @@ public Page testRecipeListByCategory(Long categoryId, Integer pageIn public Boolean deleteTestRecipe() { List findRecipes = testRecipeRepository.findAll(); - List thumbnailUrls = findRecipes.stream().map(recipe -> recipe.getThumbnailUrl()).collect(Collectors.toList()); - List stepUrlList = testStepRepository.findAll().stream() + List thumbnailUrls = findRecipes.stream().parallel() + .map(recipe -> recipe.getThumbnailUrl()).collect(Collectors.toList()); + List stepUrlList = testStepRepository.findAll().stream().parallel() .filter(steps -> steps.getImageUrl() != null) .map(step -> step.getImageUrl()) .collect(Collectors.toList()); testRecipeRepository.deleteAll(); - thumbnailUrls.forEach(thumbnailUrl -> amazonS3Manager.deleteFile(RecipeConverter.toKeyName(thumbnailUrl).substring(1))); - stepUrlList + thumbnailUrls.parallelStream().forEach(thumbnailUrl -> amazonS3Manager.deleteFile(RecipeConverter.toKeyName(thumbnailUrl).substring(1))); + stepUrlList.parallelStream() .forEach(stepUrl -> amazonS3Manager.deleteFile(RecipeConverter.toKeyName(stepUrl).substring(1))); return testRecipeRepository.count() == 0;