Skip to content

Commit

Permalink
Merge pull request #297 from zipdabang/refactor/296
Browse files Browse the repository at this point in the history
♻️  Refactor/296 ParallelStream 추가
  • Loading branch information
Hanvp authored Jan 30, 2024
2 parents 2bced15 + ed5737e commit 162a17d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public static TestRecipe toTestRecipe(RecipeRequestDto.CreateRecipeDto request,
}

public static List<TestRecipeCategoryMapping> toTestRecipeCategory(List<Long> categoryIds, TestRecipe recipe) {
return categoryIds.stream()
return categoryIds.stream().parallel()
.map(recipeCategoryId -> toTestRecipeCategoryMappingDto(recipeCategoryId, recipe))
.collect(Collectors.toList());
}
Expand All @@ -760,7 +760,7 @@ private static TestRecipeCategoryMapping toTestRecipeCategoryMappingDto(Long cat
}

public static List<TestStep> toTestStep(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe, List<MultipartFile> stepImages) {
return request.getSteps().stream()
return request.getSteps().stream().parallel()
.map(step-> {
if (step.getDescription() == null)
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
Expand Down Expand Up @@ -801,7 +801,7 @@ private static TestStep toTestStepDto(RecipeRequestDto.StepDto step, TestRecipe
}

public static List<TestIngredient> toTestIngredient(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe) {
return request.getIngredients().stream()
return request.getIngredients().stream().parallel()
.map(ingredient -> toTestIngredientDto(ingredient, recipe))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ public TestRecipe getTestRecipe(Long recipeId) {
return findRecipe;
}

@Transactional(readOnly = false)
@Transactional
@Override
public Page<TestRecipe> testRecipeListByCategory(Long categoryId, Integer pageIndex, String order) {

Expand Down Expand Up @@ -970,16 +970,17 @@ public Page<TestRecipe> testRecipeListByCategory(Long categoryId, Integer pageIn
public Boolean deleteTestRecipe() {
List<TestRecipe> findRecipes = testRecipeRepository.findAll();

List<String> thumbnailUrls = findRecipes.stream().map(recipe -> recipe.getThumbnailUrl()).collect(Collectors.toList());
List<String> stepUrlList = testStepRepository.findAll().stream()
List<String> thumbnailUrls = findRecipes.stream().parallel()
.map(recipe -> recipe.getThumbnailUrl()).collect(Collectors.toList());
List<String> 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;
Expand Down

0 comments on commit 162a17d

Please sign in to comment.