Skip to content

Commit

Permalink
[refac] optimize query execution by reducing select queries
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Jan 6, 2025
1 parent d21b4a3 commit 51ebbb4
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public void modifyMenu(final MenuPatchCommand command) {
@Transactional
public MenusPostResponse createMenus(final MenusPostCommand command) {
Store findStore = storeFinder.findByIdWhereDeletedIsFalse(command.storeId());
List<Menu> allMenus = menuFinder.findAllByStore(findStore);
List<Menu> menus = command.menu().stream()
.filter(c -> !validateMenuConflict(findStore, c.name()))
.filter(c -> !validateMenuConflict(allMenus, c.name()))
.map(c -> Menu.create(findStore, c.name(), c.price()))
.toList();
menuUpdater.saveAll(menus);
Expand All @@ -69,8 +70,8 @@ private void updateLowestPriceInStore(final Store findStore) {
findStore.updateLowestPrice(menuFinder.findLowestPriceByStore(findStore));
}

private boolean validateMenuConflict(final Store store, final String menuName) {
return menuFinder.existsByStoreAndName(store, menuName);
private boolean validateMenuConflict(final List<Menu> menus, final String menuName) {
return menus.stream().anyMatch(menu -> menu.getName().equals(menuName));
}

private void checkNoMenuInStore(final Store store, final long userId) {
Expand Down

0 comments on commit 51ebbb4

Please sign in to comment.