Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

조회 성능 개선 revert #70

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package com.app.domain.categorizedproblem.repository;

import com.app.domain.categorizedproblem.entity.CategorizedProblem;
import feign.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import org.springframework.data.jpa.repository.Query;

public interface CategorizedProblemRepository extends JpaRepository<CategorizedProblem, Long> {
boolean existsByCategoryCategoryIdAndProblemProblemId(Long categoryId, Long problemId);

boolean existsByProblemProblemId(Long problemId);

@Query(value = "SELECT cp FROM CategorizedProblem cp JOIN FETCH cp.problem p JOIN FETCH cp.category c WHERE c.categoryId = :categoryId",
countQuery = "SELECT count(cp) FROM CategorizedProblem cp WHERE cp.category.categoryId = :categoryId")
Page<CategorizedProblem> findByCategoryCategoryId(@Param("categoryId") Long categoryId, Pageable pageable);
Page<CategorizedProblem> findByCategoryCategoryId(Long categoryId, Pageable pageable);

List<CategorizedProblem> findByCategoryCategoryId(Long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -245,7 +244,6 @@ public CategorizedProblem updateCategorizedProblem(Long categorizedProblemId, Me
}

@Transactional(readOnly = true)
@Cacheable(value = "categorizedProblem", key = "#categoryId")
public Page<CategorizedProblem> findCategorizedProblemsByCategoryId(Long categoryId, int page, int size) {
PageRequest pageRequest = PageRequest.of(page, size);
return categorizedProblemRepository.findByCategoryCategoryId(categoryId, pageRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.app.domain.categorizedsummary.repository;

import com.app.domain.categorizedsummary.entity.CategorizedSummary;
import feign.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface CategorizedSummaryRepository extends JpaRepository<CategorizedSummary, Long> {
boolean existsByCategoryCategoryIdAndSummarySummaryId(Long categoryId, Long summaryId);

boolean existsBySummarySummaryId(Long summaryId);

@Query(value = "SELECT cs FROM CategorizedSummary cs JOIN FETCH cs.summary s JOIN FETCH cs.category c WHERE c.categoryId = :categoryId",
countQuery = "SELECT count(cs) FROM CategorizedSummary cs WHERE cs.category.categoryId = :categoryId")
Page<CategorizedSummary> findByCategoryCategoryId(@Param("categoryId") Long categoryId, Pageable pageable);
Page<CategorizedSummary> findByCategoryCategoryId(Long categoryId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -105,8 +104,6 @@ public CategorizedSummary findVerifiedCategorizedSummaryByCategorizedSummaryId(L
.orElseThrow(() -> new EntityNotFoundException(ErrorCode.CATEGORIZED_SUMMARY_NOT_EXISTS));
}

@Transactional(readOnly = true)
@Cacheable(value = "categorizedSummary", key = "#categoryId")
public Page<CategorizedSummary> findCategorziedSummarysByCategoryId(Long categoryId, int page, int size) {
PageRequest pageRequest = PageRequest.of(page, size);
return categorizedSummaryRepository.findByCategoryCategoryId(categoryId, pageRequest);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/app/domain/category/entity/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class Category extends BaseEntity {
@Column(nullable = false, length = 10)
private CategoryType categoryType;

@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
@OneToMany(mappedBy = "category")
private List<CategorizedSummary> categorizedSummaries;

@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
@OneToMany(mappedBy = "category")
private List<CategorizedProblem> categorizedProblems;

public void updateMember(Member member) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/app/domain/file/entity/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class File extends BaseEntity {
//@Column(name = "MEMBER_ID") //추후에 Members 엔티티와 연결
//private String memberId;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne
@JoinColumn(name = "MEMBER_ID")
private Member member;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.AllArgsConstructor;
Expand All @@ -21,7 +20,7 @@
public class AiGeneratedProblem extends Problem {

@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne
@JoinColumn(name = "FILE_ID")
private ProblemFile problemFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class ProblemFile extends File {


@OneToMany(mappedBy = "problemFile", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@OneToMany(mappedBy = "problemFile", cascade = CascadeType.ALL, orphanRemoval = true)
private List<AiGeneratedProblem> aiQuestions;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.app.domain.summary.entity.Summary;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.AllArgsConstructor;
Expand All @@ -22,7 +21,7 @@
@Entity
public class AiGeneratedSummary extends Summary {

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne
@JoinColumn(name = "FILE_ID")
private SummaryFile summaryFile;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@DiscriminatorValue("SUMMARY")
public class SummaryFile extends File {

@OneToMany(mappedBy = "summaryFile", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@OneToMany(mappedBy = "summaryFile", cascade = CascadeType.ALL, orphanRemoval = true)
private List<AiGeneratedSummary> aiQuestions;

@Column(name = "SUMMARY_AMOUNT", nullable = false)
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/app/global/config/CacheConfig.java

This file was deleted.

Loading