성능개선
This commit is contained in:
parent
8d1f0e7098
commit
0a57a2cef1
|
|
@ -53,6 +53,8 @@ export interface ExecutionContext {
|
|||
nodeResults: Map<string, NodeResult>;
|
||||
executionOrder: string[];
|
||||
buttonContext?: ButtonContext;
|
||||
// 🆕 현재 실행 중인 소스 노드의 dataSourceType (context-data | table-all)
|
||||
currentNodeDataSourceType?: string;
|
||||
}
|
||||
|
||||
export interface ButtonContext {
|
||||
|
|
@ -683,6 +685,9 @@ export class NodeFlowExecutionService {
|
|||
// 🆕 노드의 dataSourceType 확인 (기본값: context-data)
|
||||
const nodeDataSourceType = dataSourceType || "context-data";
|
||||
|
||||
// 🆕 ExecutionContext에 현재 소스 노드의 dataSourceType 저장
|
||||
context.currentNodeDataSourceType = nodeDataSourceType;
|
||||
|
||||
logger.info(
|
||||
`🔌 외부 DB 소스 노드 실행: ${connectionId}.${tableName}, dataSourceType=${nodeDataSourceType}`
|
||||
);
|
||||
|
|
@ -785,6 +790,9 @@ export class NodeFlowExecutionService {
|
|||
// 🆕 노드의 dataSourceType 확인 (기본값: context-data)
|
||||
const nodeDataSourceType = dataSourceType || "context-data";
|
||||
|
||||
// 🆕 ExecutionContext에 현재 소스 노드의 dataSourceType 저장
|
||||
context.currentNodeDataSourceType = nodeDataSourceType;
|
||||
|
||||
logger.info(
|
||||
`📊 테이블 소스 노드 실행: ${tableName}, dataSourceType=${nodeDataSourceType}`
|
||||
);
|
||||
|
|
@ -1323,6 +1331,66 @@ export class NodeFlowExecutionService {
|
|||
let updatedCount = 0;
|
||||
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) {
|
||||
const setClauses: string[] = [];
|
||||
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(
|
||||
whereConditions,
|
||||
data,
|
||||
|
|
@ -1690,10 +1759,44 @@ export class NodeFlowExecutionService {
|
|||
let deletedCount = 0;
|
||||
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) {
|
||||
console.log("🔍 WHERE 조건 처리 중...");
|
||||
|
||||
// 🆕 WHERE 조건 자동 보강: Primary Key 추가
|
||||
// 🔑 Primary Key 자동 추가 (context-data 모드)
|
||||
console.log("🔑 context-data 모드: Primary Key 자동 추가");
|
||||
const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK(
|
||||
whereConditions,
|
||||
data,
|
||||
|
|
|
|||
Loading…
Reference in New Issue