Skip to content

Commit

Permalink
Revert "Merge pull request #70 from capstone-five-ai/revert/performan…
Browse files Browse the repository at this point in the history
…ce-approve"

This reverts commit 6494039, reversing
changes made to 093ec44.
  • Loading branch information
yujamint committed Jun 16, 2024
1 parent 6494039 commit 9168087
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
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);

Page<CategorizedProblem> findByCategoryCategoryId(Long categoryId, Pageable pageable);
@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);

List<CategorizedProblem> findByCategoryCategoryId(Long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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 @@ -244,6 +245,7 @@ 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,14 +1,18 @@
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);

Page<CategorizedSummary> findByCategoryCategoryId(Long categoryId, Pageable pageable);
@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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 @@ -104,6 +105,8 @@ 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")
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
private List<CategorizedSummary> categorizedSummaries;

@OneToMany(mappedBy = "category")
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
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
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MEMBER_ID")
private Member member;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 @@ -20,7 +21,7 @@
public class AiGeneratedProblem extends Problem {

@JsonIgnore
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@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)
@OneToMany(mappedBy = "problemFile", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<AiGeneratedProblem> aiQuestions;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 @@ -21,7 +22,7 @@
@Entity
public class AiGeneratedSummary extends Summary {

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@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)
@OneToMany(mappedBy = "summaryFile", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<AiGeneratedSummary> aiQuestions;

@Column(name = "SUMMARY_AMOUNT", nullable = false)
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/app/global/config/CacheConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.app.global.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class CacheConfig extends CachingConfigurerSupport {
@Bean
@Override
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("categorizedProblem", "categorizedSummary");
}
}

0 comments on commit 9168087

Please sign in to comment.