Skip to content

Commit 93cb4f8

Browse files
committed
fix: correct progress calculation when using worker-based generation
1 parent 403fccf commit 93cb4f8

3 files changed

Lines changed: 9 additions & 53 deletions

File tree

src/main/services/data-generator/data-generator-service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export async function runDataGenerator(
4444
const schema = await fetchSchema(projectId)
4545

4646
const ruleIds = new Set<number>()
47+
let totalRows = 0
48+
let progressRows = 0
4749
for (const table of tables) {
50+
totalRows += table.recordCnt
4851
for (const column of table.columns) {
4952
if (
5053
(column.dataSource === 'FAKER' || column.dataSource === 'AI') &&
@@ -133,6 +136,11 @@ export async function runDataGenerator(
133136
if (data.type) {
134137
if (data.type === 'worker-result') {
135138
results.push(data.result)
139+
} else if (data.type === 'row-progress') {
140+
progressRows += data.progress
141+
const progress = Math.floor((progressRows / totalRows) * 100)
142+
data.progress = progress
143+
mainWindow.webContents.send('data-generator:progress', data)
136144
} else {
137145
mainWindow.webContents.send('data-generator:progress', data)
138146
}

src/main/services/data-generator/worker-runner.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
347347
}
348348

349349
logger.info(`[${tableName}] 시작: ${recordCnt.toLocaleString()}행, ${columns.length}컬럼`)
350-
const startTime = Date.now()
351350
let totalProcessed = 0
352351
const numChunks = Math.max(1, Math.ceil(recordCnt / CHUNK_SIZE))
353352

@@ -359,22 +358,16 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
359358
continue
360359
}
361360

362-
logger.info(`\n[${tableName}] 청크 ${chunkIdx + 1}/${numChunks} 처리 중 (${chunkSize}행)`)
363-
const chunkStartTime = Date.now()
364-
365361
const columnStreams = columns.map((col) => createColumnStream(col, task, chunkSize))
366362
const { aiColumns, nonAiColumns } = separateColumnsByType(columns)
367363
const chunkColumnValues: (string | typeof INVALID)[][] = new Array(columns.length)
368364

369365
// === Non-AI 컬럼 처리 (예외 처리 일관화) ===
370366
if (nonAiColumns.length > 0) {
371-
logger.info(`[${tableName}] Non-AI 컬럼 동시 처리:`)
372367
const nonAiResults = await Promise.all(
373368
nonAiColumns.map(async (colIdx) => {
374369
const col = columns[colIdx]
375370
const stream = columnStreams[colIdx]
376-
const colStart = Date.now()
377-
logger.info(` ▶ [${col.columnName}] 처리 (${col.dataSource})`)
378371

379372
const values: (string | typeof INVALID)[] = []
380373
for (let i = 0; i < chunkSize; i++) {
@@ -394,9 +387,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
394387
}
395388
}
396389

397-
const colDuration = ((Date.now() - colStart) / 1000).toFixed(2)
398-
logger.info(` ✓ [${col.columnName}] 완료 (${colDuration}초)`)
399-
400390
return { colIdx, values }
401391
})
402392
)
@@ -408,17 +398,13 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
408398

409399
// === AI 컬럼 처리 (동시 MAX_AI_CONCURRENT개, 예외 처리 통일) ===
410400
if (aiColumns.length > 0) {
411-
logger.info(`[${tableName}] AI 컬럼 처리 (동시 ${MAX_AI_CONCURRENT}개):`)
412-
413401
for (let i = 0; i < aiColumns.length; i += MAX_AI_CONCURRENT) {
414402
const batch = aiColumns.slice(i, i + MAX_AI_CONCURRENT)
415403

416404
const batchResults = await Promise.all(
417405
batch.map(async (colIdx) => {
418406
const col = columns[colIdx]
419407
const stream = columnStreams[colIdx]
420-
const colStart = Date.now()
421-
logger.info(` ▶ [${col.columnName}] 처리 (${col.dataSource})`)
422408

423409
const values: (string | typeof INVALID)[] = []
424410
for (let j = 0; j < chunkSize; j++) {
@@ -438,9 +424,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
438424
}
439425
}
440426

441-
const colDuration = ((Date.now() - colStart) / 1000).toFixed(2)
442-
logger.info(` ✓ [${col.columnName}] 완료 (${colDuration}초)`)
443-
444427
return { colIdx, values }
445428
})
446429
)
@@ -450,7 +433,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
450433
})
451434

452435
if (i + MAX_AI_CONCURRENT < aiColumns.length) {
453-
logger.info(` … 다음 AI 컬럼 대기 (1초)...`)
454436
await new Promise((res) => setTimeout(res, 1000))
455437
}
456438
}
@@ -529,47 +511,18 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
529511
totalProcessed += successOnThisChunk // 성공한 row만 증가
530512
totalFailed += failedOnThisChunk // fallback에서 실패한 row
531513

532-
process.parentPort.postMessage({
533-
type: 'row-delta',
534-
tableName,
535-
success: successOnThisChunk,
536-
fail: failedOnThisChunk
537-
})
538-
539514
await fs.promises.appendFile(sqlPath, bulkSQL + '\n', 'utf8')
540515
}
541516

542-
const chunkDuration = ((Date.now() - chunkStartTime) / 1000).toFixed(2)
543-
logger.info(`\n[${tableName}] 청크 ${chunkIdx + 1} 완료 (${chunkDuration}초)`)
544-
545-
const progressPercent =
546-
chunkIdx + 1 === numChunks ? 100 : Math.floor((chunkEnd / recordCnt) * 100)
547-
548517
process.parentPort.postMessage({
549518
type: 'row-progress',
550519
tableName,
551-
progress: progressPercent
520+
progress: chunkSize
552521
})
553522

554523
await new Promise((res) => setTimeout(res, 100))
555-
556-
if (chunkEnd === recordCnt) {
557-
columns.forEach((col) => {
558-
process.parentPort.postMessage({
559-
type: 'column-progress',
560-
tableName,
561-
columnName: col.columnName,
562-
progress: 100
563-
})
564-
})
565-
}
566524
}
567525

568-
const totalDuration = ((Date.now() - startTime) / 1000).toFixed(2)
569-
logger.info(
570-
`\n[${tableName}] 전체 완료 (${totalDuration}초, ${totalProcessed.toLocaleString()}행)`
571-
)
572-
573526
if (directContext) {
574527
await directContext.commit()
575528
await directContext.close()

src/renderer/src/views/DummyInsertView.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ const DummyInsertView: React.FC = () => {
8686
setProgress(message.progress)
8787
}
8888

89-
if (message.type === 'row-delta') {
90-
setSuccessRows((prev) => prev + (message.successDelta ?? 0))
91-
setFailedRows((prev) => prev + (message.failDelta ?? 0))
92-
}
93-
9489
if (message.type === 'table-complete' && message.tableName) {
9590
const hasFail = (message.failedRows ?? 0) > 0
9691

0 commit comments

Comments
 (0)