Skip to content

Commit

Permalink
hotfix: PlayerRepository.findAll() 호출 시 N+1 문제 수정 (#360)
Browse files Browse the repository at this point in the history
* refactor: Player의 Member 필드 지연로딩으로 변경

* refactor: PlayerRepository.findAll() Fetch Join 진행

* test: 지연 로딩으로 인한 테스트 에러 임시 수정
  • Loading branch information
dooboocookie committed Oct 3, 2023
1 parent deb80bb commit 04e6af4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Player extends BaseEntity {
private Score totalScore;

@JoinColumn(name = "member_id")
@OneToOne
@OneToOne(fetch = FetchType.LAZY)
private Member member;

private boolean deleted = FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import com.now.naaga.player.domain.Player;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface PlayerRepository extends JpaRepository<Player, Long> {

List<Player> findByMemberId(final Long memberId);

@Override
@Query("SELECT p FROM Player p JOIN FETCH p.member")
List<Player> findAll();
}
4 changes: 2 additions & 2 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ spring:

spring:
config:
import: classpath:security/application-prod.yml
import: classpath:security/application-local.yml
activate:
on-profile: prod
on-profile: local
2 changes: 1 addition & 1 deletion backend/src/main/resources/security
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;

@SuppressWarnings("NonAsciiCharacters")
@DisplayNameGeneration(ReplaceUnderscores.class)
Expand All @@ -42,6 +43,7 @@ class HintServiceTest {
@Autowired
private PlaceBuilder placeBuilder;

@Transactional
@Test
void 힌트를_생성한다() {
// given
Expand Down

0 comments on commit 04e6af4

Please sign in to comment.