Skip to content

Commit

Permalink
fix : Tag . Category N + 1문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
dltjdgh0428 committed Apr 19, 2024
1 parent 3edaeab commit 23fbd2a
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@RequiredArgsConstructor
@Configuration
//@EnableRedisRepositories
@EnableRedisRepositories
public class RedisConfig {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers("/").permitAll()
// 테스트 관련 url
// .requestMatchers("/api/**").permitAll()
.requestMatchers("/api/**").permitAll()
.requestMatchers("/health", "/env", "/test/**", "/swagger-ui/**").permitAll()
.requestMatchers("/api/reviews").permitAll()
// 비회원도 볼수있는 url
.requestMatchers("/api/review", "/api/map", "/api/tags", "/api/data/**").permitAll()
// 나머지
// .requestMatchers("/api/**").hasAuthority("ROLE_MEMBER")
.anyRequest().authenticated()
// .anyRequest().authenticated()
)
.oauth2Login(oauth2Login ->
oauth2Login
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class PinServiceImpl implements PinService {
.map(tagged -> new TagCountRespDto(
(String) tagged[0],
(Long) tagged[1])).toList();

return PinWithTagCountRespDto.toDto(pin, tagCountRespDtos);
}).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class Review extends BaseTimeEntity {
@Column(nullable = false)
private boolean isBookComplete;


@Transient // 칼럼이 만들어지지 않는다.
private Long likeCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import org.springframework.data.repository.query.Param;

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

public interface ReviewRepository extends JpaRepository<Review, Long> {

//공유 목록에서의 모든 독후감 조회
List<Review> findByIsPrivateOrderByCreatedDateDesc(boolean isPrivate);

Optional<Review> findById(Long reviewId);

// 개인지도에서 핀을 눌렀을때 독후감이 모두 뜨는 기능
// Entity 바뀐다면 수정 필요 -> 수정완료
@Query("SELECT review FROM Review review WHERE review.user.socialId = :socialId AND review.pin.id = :pinId ORDER BY review.createdDate DESC")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ public class Category extends BaseTimeEntity {

private String name;


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class Tag extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "tag_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.book_everywhere.domain.tag.repository;

import com.book_everywhere.domain.tag.entity.Tag;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TagRepository extends JpaRepository<Tag, Long> {

// content를 통해 가져옴
@Query("SELECT tag FROM Tag tag WHERE tag.content = :content")
Tag mFindTagByName(@Param("content") String content);


@Query("SELECT t FROM Tag t JOIN FETCH t.category")
List<Tag> findAllWithCategory();

@EntityGraph(attributePaths = {"category"})
List<Tag> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class TaggedServiceImpl implements TaggedService {

@Override
public List<TagDto> 모든태그조회() {
List<Tag> tags = tagRepository.findAll();
List<Tag> tags = tagRepository.findAllWithCategory();
return tags.stream().map(tag -> new TagDto(
tag.getContent(),
false,
Expand Down
7 changes: 3 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ spring:
data:
redis:
repositories:
enabled: false
jpa:
repositories:
bootstrap-mode: deferred
enabled: false


server:
env: blue
Expand Down Expand Up @@ -116,6 +114,7 @@ logging:
org:
springframework:
security: DEBUG
cache: DEBUG
hibernate:
type: trace

0 comments on commit 23fbd2a

Please sign in to comment.