Fix : N + 1 문제 해결
This commit is contained in:
parent
6c46b64ce2
commit
6c2c0670ab
@ -45,7 +45,7 @@ public class FolderResponse {
|
||||
|
||||
public static FolderResponse fromWithNeedReview(final Folder folder) {
|
||||
List<ImageResponse> images = folder.getImageList().stream()
|
||||
.filter(image -> image.getStatus() == LabelStatus.NEED_REVIEW)
|
||||
.filter(image -> image.getStatus() == LabelStatus.REVIEW_REQUEST)
|
||||
.map(ImageResponse::from)
|
||||
.toList();
|
||||
|
||||
|
@ -2,6 +2,8 @@ package com.worlabel.domain.folder.repository;
|
||||
|
||||
import com.worlabel.domain.folder.entity.Folder;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
@ -10,9 +12,20 @@ import java.util.Optional;
|
||||
@Repository
|
||||
public interface FolderRepository extends JpaRepository<Folder, Integer> {
|
||||
|
||||
List<Folder> findAllByProjectIdAndParentIsNull(Integer projectId);
|
||||
@Query("SELECT f FROM Folder f " +
|
||||
"LEFT JOIN FETCH f.imageList i " +
|
||||
"LEFT JOIN FETCH i.label " +
|
||||
"WHERE f.project.id = :projectId " +
|
||||
"AND f.parent IS NULL ")
|
||||
List<Folder> findAllByProjectIdAndParentIsNull(@Param("projectId") Integer projectId);
|
||||
|
||||
@Query("SELECT f FROM Folder f " +
|
||||
"LEFT JOIN FETCH f.imageList i " +
|
||||
"LEFT JOIN FETCH i.label " +
|
||||
"WHERE f.project.id = :projectId " +
|
||||
"AND f.id = :folderId")
|
||||
Optional<Folder> findAllByProjectIdAndId(@Param("projectId") Integer projectId, @Param("folderId") Integer folderId);
|
||||
|
||||
Optional<Folder> findAllByProjectIdAndId(Integer projectId, Integer folderId);
|
||||
|
||||
boolean existsByIdAndProjectId(Integer folderId, Integer projectId);
|
||||
}
|
@ -46,7 +46,7 @@ public class Image extends BaseEntity {
|
||||
*/
|
||||
@Column(name = "status", nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private LabelStatus status = LabelStatus.Pending;
|
||||
private LabelStatus status = LabelStatus.PENDING;
|
||||
|
||||
/**
|
||||
* 속한 폴더
|
||||
@ -59,7 +59,7 @@ public class Image extends BaseEntity {
|
||||
/**
|
||||
* 이미지에 연결된 레이블
|
||||
*/
|
||||
@OneToOne(mappedBy = "image", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "image", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Label label;
|
||||
|
||||
private Image(final String imageTitle, final String imageUrl, final Integer order, final Folder folder) {
|
||||
|
@ -4,9 +4,10 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum LabelStatus {
|
||||
Pending,
|
||||
PENDING,
|
||||
IN_PROGRESS,
|
||||
NEED_REVIEW,
|
||||
SAVE,
|
||||
REVIEW_REQUEST,
|
||||
COMPLETED;
|
||||
|
||||
// 입력 값을 enum 값과 일치시키기 위해 대소문자 구분 없이 변환
|
||||
|
@ -40,8 +40,4 @@ public class Label extends BaseEntity {
|
||||
label.image = image;
|
||||
return label;
|
||||
}
|
||||
|
||||
public void changeUrl(String newUrl){
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user