Skip to content

Commit

Permalink
🎨 Refactor: 유저 검색 기능 JPA N+1 문제 해결 (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
win-luck committed Jan 16, 2024
1 parent 39e4697 commit 4373f75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/diareat/diareat/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class User implements UserDetails {

// Jwt 전용 설정 (UserDetails 인터페이스 구현)

@ElementCollection(fetch = FetchType.EAGER) //roles 컬렉션
@ElementCollection(fetch = FetchType.LAZY) //roles 컬렉션
private List<String> roles = new ArrayList<>();

@Override //사용자의 권한 목록 리턴
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.diareat.diareat.user.repository;

import com.diareat.diareat.user.domain.User;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {

@EntityGraph(attributePaths = {"roles"})
List<User> findAllByNameContaining(String name); // 회원이 팔로우를 위해 검색한 유저 목록 조회

boolean existsByName(String name); // 회원가입 시 닉네임 중복 확인
boolean existsByKeyCode(String keyCode); // 카카오 회원가입 시 중복 확인
Optional<User> findByKeyCode(String keyCode); // 카카오 회원가입 시 중복 확인
Expand Down

0 comments on commit 4373f75

Please sign in to comment.