조인기능 최적화
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
BatchLookupRequest,
|
||||
BatchLookupResponse,
|
||||
} from "../types/tableManagement";
|
||||
import { referenceCacheService } from "./referenceCacheService";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -151,6 +152,44 @@ export class EntityJoinService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 조인 전략 결정 (테이블 크기 기반)
|
||||
*/
|
||||
async determineJoinStrategy(
|
||||
joinConfigs: EntityJoinConfig[]
|
||||
): Promise<"full_join" | "cache_lookup" | "hybrid"> {
|
||||
try {
|
||||
const strategies = await Promise.all(
|
||||
joinConfigs.map(async (config) => {
|
||||
// 참조 테이블의 캐시 가능성 확인
|
||||
const cachedData = await referenceCacheService.getCachedReference(
|
||||
config.referenceTable,
|
||||
config.referenceColumn,
|
||||
config.displayColumn
|
||||
);
|
||||
|
||||
return cachedData ? "cache" : "join";
|
||||
})
|
||||
);
|
||||
|
||||
// 모두 캐시 가능한 경우
|
||||
if (strategies.every((s) => s === "cache")) {
|
||||
return "cache_lookup";
|
||||
}
|
||||
|
||||
// 혼합인 경우
|
||||
if (strategies.includes("cache") && strategies.includes("join")) {
|
||||
return "hybrid";
|
||||
}
|
||||
|
||||
// 기본은 조인
|
||||
return "full_join";
|
||||
} catch (error) {
|
||||
logger.error("조인 전략 결정 실패", error);
|
||||
return "full_join"; // 안전한 기본값
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 조인 설정 유효성 검증
|
||||
*/
|
||||
@@ -263,35 +302,6 @@ export class EntityJoinService {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity 조인 전략 결정 (full_join vs cache_lookup)
|
||||
*/
|
||||
async determineJoinStrategy(
|
||||
joinConfigs: EntityJoinConfig[]
|
||||
): Promise<"full_join" | "cache_lookup"> {
|
||||
try {
|
||||
// 참조 테이블 크기 확인
|
||||
for (const config of joinConfigs) {
|
||||
const result = (await prisma.$queryRawUnsafe(`
|
||||
SELECT COUNT(*) as count
|
||||
FROM ${config.referenceTable}
|
||||
`)) as Array<{ count: bigint }>;
|
||||
|
||||
const count = Number(result[0]?.count || 0);
|
||||
|
||||
// 1000건 이상이면 조인 방식 사용
|
||||
if (count > 1000) {
|
||||
return "full_join";
|
||||
}
|
||||
}
|
||||
|
||||
return "cache_lookup";
|
||||
} catch (error) {
|
||||
logger.error("조인 전략 결정 실패", error);
|
||||
return "full_join"; // 기본값
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const entityJoinService = new EntityJoinService();
|
||||
|
||||
Reference in New Issue
Block a user