성능개선

This commit is contained in:
kjs 2025-10-24 14:24:18 +09:00
parent 8d1f0e7098
commit 0a57a2cef1
1 changed files with 105 additions and 2 deletions

View File

@ -53,6 +53,8 @@ export interface ExecutionContext {
nodeResults: Map<string, NodeResult>; nodeResults: Map<string, NodeResult>;
executionOrder: string[]; executionOrder: string[];
buttonContext?: ButtonContext; buttonContext?: ButtonContext;
// 🆕 현재 실행 중인 소스 노드의 dataSourceType (context-data | table-all)
currentNodeDataSourceType?: string;
} }
export interface ButtonContext { export interface ButtonContext {
@ -683,6 +685,9 @@ export class NodeFlowExecutionService {
// 🆕 노드의 dataSourceType 확인 (기본값: context-data) // 🆕 노드의 dataSourceType 확인 (기본값: context-data)
const nodeDataSourceType = dataSourceType || "context-data"; const nodeDataSourceType = dataSourceType || "context-data";
// 🆕 ExecutionContext에 현재 소스 노드의 dataSourceType 저장
context.currentNodeDataSourceType = nodeDataSourceType;
logger.info( logger.info(
`🔌 외부 DB 소스 노드 실행: ${connectionId}.${tableName}, dataSourceType=${nodeDataSourceType}` `🔌 외부 DB 소스 노드 실행: ${connectionId}.${tableName}, dataSourceType=${nodeDataSourceType}`
); );
@ -785,6 +790,9 @@ export class NodeFlowExecutionService {
// 🆕 노드의 dataSourceType 확인 (기본값: context-data) // 🆕 노드의 dataSourceType 확인 (기본값: context-data)
const nodeDataSourceType = dataSourceType || "context-data"; const nodeDataSourceType = dataSourceType || "context-data";
// 🆕 ExecutionContext에 현재 소스 노드의 dataSourceType 저장
context.currentNodeDataSourceType = nodeDataSourceType;
logger.info( logger.info(
`📊 테이블 소스 노드 실행: ${tableName}, dataSourceType=${nodeDataSourceType}` `📊 테이블 소스 노드 실행: ${tableName}, dataSourceType=${nodeDataSourceType}`
); );
@ -1323,6 +1331,66 @@ export class NodeFlowExecutionService {
let updatedCount = 0; let updatedCount = 0;
const updatedDataArray: any[] = []; const updatedDataArray: any[] = [];
// 🆕 table-all 모드: 단일 SQL로 일괄 업데이트
if (context.currentNodeDataSourceType === "table-all") {
console.log("🚀 table-all 모드: 단일 SQL로 일괄 업데이트 시작");
// 첫 번째 데이터를 참조하여 SET 절 생성
const firstData = dataArray[0];
const setClauses: string[] = [];
const values: any[] = [];
let paramIndex = 1;
console.log("🗺️ 필드 매핑 처리 중...");
fieldMappings.forEach((mapping: any) => {
const value =
mapping.staticValue !== undefined
? mapping.staticValue
: firstData[mapping.sourceField];
console.log(
` ${mapping.sourceField}${mapping.targetField}: ${value === undefined ? "❌ undefined" : "✅ " + value}`
);
if (mapping.targetField) {
setClauses.push(`${mapping.targetField} = $${paramIndex}`);
values.push(value);
paramIndex++;
}
});
// WHERE 조건 (사용자 정의 조건만 사용, PK 자동 추가 안 함)
const whereResult = this.buildWhereClause(
whereConditions,
firstData,
paramIndex
);
values.push(...whereResult.values);
const sql = `
UPDATE ${targetTable}
SET ${setClauses.join(", ")}
${whereResult.clause}
`;
console.log("📝 실행할 SQL (일괄 처리):", sql);
console.log("📊 바인딩 값:", values);
const result = await txClient.query(sql, values);
updatedCount = result.rowCount || 0;
logger.info(
`✅ UPDATE 완료 (내부 DB, 일괄 처리): ${targetTable}, ${updatedCount}`
);
// 업데이트된 데이터는 원본 배열 반환 (실제 DB에서 다시 조회하지 않음)
return dataArray;
}
// 🆕 context-data 모드: 개별 업데이트 (PK 자동 추가)
console.log("🎯 context-data 모드: 개별 업데이트 시작");
for (const data of dataArray) { for (const data of dataArray) {
const setClauses: string[] = []; const setClauses: string[] = [];
const values: any[] = []; const values: any[] = [];
@ -1357,7 +1425,8 @@ export class NodeFlowExecutionService {
} }
}); });
// 🆕 WHERE 조건 자동 보강: Primary Key 추가 // 🔑 Primary Key 자동 추가 (context-data 모드)
console.log("🔑 context-data 모드: Primary Key 자동 추가");
const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK( const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK(
whereConditions, whereConditions,
data, data,
@ -1690,10 +1759,44 @@ export class NodeFlowExecutionService {
let deletedCount = 0; let deletedCount = 0;
const deletedDataArray: any[] = []; const deletedDataArray: any[] = [];
// 🆕 table-all 모드: 단일 SQL로 일괄 삭제
if (context.currentNodeDataSourceType === "table-all") {
console.log("🚀 table-all 모드: 단일 SQL로 일괄 삭제 시작");
// 첫 번째 데이터를 참조하여 WHERE 절 생성
const firstData = dataArray[0];
// WHERE 조건 (사용자 정의 조건만 사용, PK 자동 추가 안 함)
const whereResult = this.buildWhereClause(whereConditions, firstData, 1);
const sql = `DELETE FROM ${targetTable} ${whereResult.clause} RETURNING *`;
console.log("📝 실행할 SQL (일괄 처리):", sql);
console.log("📊 바인딩 값:", whereResult.values);
const result = await txClient.query(sql, whereResult.values);
deletedCount = result.rowCount || 0;
// 🔥 RETURNING으로 받은 삭제된 데이터 저장
if (result.rows && result.rows.length > 0) {
deletedDataArray.push(...result.rows);
}
logger.info(
`✅ DELETE 완료 (내부 DB, 일괄 처리): ${targetTable}, ${deletedCount}`
);
return deletedDataArray;
}
// 🆕 context-data 모드: 개별 삭제 (PK 자동 추가)
console.log("🎯 context-data 모드: 개별 삭제 시작");
for (const data of dataArray) { for (const data of dataArray) {
console.log("🔍 WHERE 조건 처리 중..."); console.log("🔍 WHERE 조건 처리 중...");
// 🆕 WHERE 조건 자동 보강: Primary Key 추가 // 🔑 Primary Key 자동 추가 (context-data 모드)
console.log("🔑 context-data 모드: Primary Key 자동 추가");
const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK( const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK(
whereConditions, whereConditions,
data, data,