추론 상세 geom-list 오래 걸리는 현상 수정
This commit is contained in:
@@ -294,8 +294,10 @@ public class InferenceDetailDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
public static class Geom {
|
public static class Geom {
|
||||||
|
|
||||||
|
Long geoUid;
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
String uid;
|
String uid;
|
||||||
Integer compareYyyy;
|
Integer compareYyyy;
|
||||||
@@ -314,6 +316,7 @@ public class InferenceDetailDto {
|
|||||||
String fitState;
|
String fitState;
|
||||||
|
|
||||||
public Geom(
|
public Geom(
|
||||||
|
Long geoUid,
|
||||||
UUID uuid,
|
UUID uuid,
|
||||||
String uid,
|
String uid,
|
||||||
Integer compareYyyy,
|
Integer compareYyyy,
|
||||||
@@ -328,6 +331,7 @@ public class InferenceDetailDto {
|
|||||||
String subUid,
|
String subUid,
|
||||||
String pnu,
|
String pnu,
|
||||||
String fitState) {
|
String fitState) {
|
||||||
|
this.geoUid = geoUid;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.uid = uid;
|
this.uid = uid;
|
||||||
this.compareYyyy = compareYyyy;
|
this.compareYyyy = compareYyyy;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalInferenceEntity;
|
|||||||
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearnEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearnEntity;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity;
|
||||||
import com.querydsl.core.BooleanBuilder;
|
import com.querydsl.core.BooleanBuilder;
|
||||||
|
import com.querydsl.core.Tuple;
|
||||||
import com.querydsl.core.types.Expression;
|
import com.querydsl.core.types.Expression;
|
||||||
import com.querydsl.core.types.Projections;
|
import com.querydsl.core.types.Projections;
|
||||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||||
@@ -37,13 +38,10 @@ import com.querydsl.core.types.dsl.CaseBuilder;
|
|||||||
import com.querydsl.core.types.dsl.Expressions;
|
import com.querydsl.core.types.dsl.Expressions;
|
||||||
import com.querydsl.core.types.dsl.NumberExpression;
|
import com.querydsl.core.types.dsl.NumberExpression;
|
||||||
import com.querydsl.core.types.dsl.StringExpression;
|
import com.querydsl.core.types.dsl.StringExpression;
|
||||||
import com.querydsl.jpa.JPAExpressions;
|
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -448,12 +446,14 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
|||||||
NumberExpression<Long> inkxNoAsLong =
|
NumberExpression<Long> inkxNoAsLong =
|
||||||
Expressions.numberTemplate(Long.class, "cast({0} as long)", mapInkx5kEntity.mapidcdNo);
|
Expressions.numberTemplate(Long.class, "cast({0} as long)", mapInkx5kEntity.mapidcdNo);
|
||||||
|
|
||||||
|
/* 미사용
|
||||||
StringExpression pnu =
|
StringExpression pnu =
|
||||||
Expressions.stringTemplate(
|
Expressions.stringTemplate(
|
||||||
"nullif(({0}), '')",
|
"nullif(({0}), '')",
|
||||||
JPAExpressions.select(Expressions.stringTemplate("string_agg({0}, ',')", pnuEntity.pnu))
|
JPAExpressions.select(Expressions.stringTemplate("string_agg({0}, ',')", pnuEntity.pnu))
|
||||||
.from(pnuEntity)
|
.from(pnuEntity)
|
||||||
.where(pnuEntity.geo.geoUid.eq(mapSheetAnalDataInferenceGeomEntity.geoUid)));
|
.where(pnuEntity.geo.geoUid.eq(mapSheetAnalDataInferenceGeomEntity.geoUid)));
|
||||||
|
*/
|
||||||
|
|
||||||
// 4) content
|
// 4) content
|
||||||
List<Geom> content =
|
List<Geom> content =
|
||||||
@@ -461,6 +461,7 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
|||||||
.select(
|
.select(
|
||||||
Projections.constructor(
|
Projections.constructor(
|
||||||
Geom.class,
|
Geom.class,
|
||||||
|
mapSheetAnalDataInferenceGeomEntity.geoUid,
|
||||||
mapSheetAnalDataInferenceGeomEntity.uuid,
|
mapSheetAnalDataInferenceGeomEntity.uuid,
|
||||||
mapSheetAnalDataInferenceGeomEntity.resultUid,
|
mapSheetAnalDataInferenceGeomEntity.resultUid,
|
||||||
mapSheetAnalDataInferenceGeomEntity.compareYyyy,
|
mapSheetAnalDataInferenceGeomEntity.compareYyyy,
|
||||||
@@ -475,7 +476,7 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
|||||||
Expressions.stringTemplate(
|
Expressions.stringTemplate(
|
||||||
"substring({0} from 1 for 8)",
|
"substring({0} from 1 for 8)",
|
||||||
mapSheetAnalDataInferenceGeomEntity.resultUid),
|
mapSheetAnalDataInferenceGeomEntity.resultUid),
|
||||||
pnu,
|
Expressions.constant(""),
|
||||||
mapSheetAnalDataInferenceGeomEntity.fitState))
|
mapSheetAnalDataInferenceGeomEntity.fitState))
|
||||||
.from(mapSheetAnalInferenceEntity)
|
.from(mapSheetAnalInferenceEntity)
|
||||||
.join(mapSheetAnalDataInferenceEntity)
|
.join(mapSheetAnalDataInferenceEntity)
|
||||||
@@ -490,6 +491,33 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
|||||||
.limit(pageable.getPageSize())
|
.limit(pageable.getPageSize())
|
||||||
.fetch();
|
.fetch();
|
||||||
|
|
||||||
|
// 4-1) pnu 를 geoUid 로 검색하기 -> AS-IS 에서는 전체 tb_pnu 를 조회해서 오래 걸렸음
|
||||||
|
List<Long> geoUids = content.stream().map(Geom::getGeoUid).filter(Objects::nonNull).toList();
|
||||||
|
Map<Long, String> pnuMap = new HashMap<>();
|
||||||
|
|
||||||
|
if (!geoUids.isEmpty()) {
|
||||||
|
StringExpression pnuAgg = Expressions.stringTemplate("string_agg({0}, ',')", pnuEntity.pnu);
|
||||||
|
|
||||||
|
List<Tuple> pnuRows =
|
||||||
|
queryFactory
|
||||||
|
.select(
|
||||||
|
pnuEntity.geo.geoUid,
|
||||||
|
Expressions.stringTemplate("string_agg({0}, ',')", pnuEntity.pnu))
|
||||||
|
.from(pnuEntity)
|
||||||
|
.where(pnuEntity.geo.geoUid.in(geoUids))
|
||||||
|
.groupBy(pnuEntity.geo.geoUid)
|
||||||
|
.fetch();
|
||||||
|
|
||||||
|
pnuMap =
|
||||||
|
pnuRows.stream()
|
||||||
|
.collect(
|
||||||
|
Collectors.toMap(row -> row.get(pnuEntity.geo.geoUid), row -> row.get(pnuAgg)));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Geom geom : content) {
|
||||||
|
geom.setPnu(pnuMap.get(geom.getGeoUid()));
|
||||||
|
}
|
||||||
|
|
||||||
// 5) total (조인 최소화 유지)
|
// 5) total (조인 최소화 유지)
|
||||||
Long total =
|
Long total =
|
||||||
queryFactory
|
queryFactory
|
||||||
|
|||||||
Reference in New Issue
Block a user