update 22
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package research.loghunter.service;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -7,6 +8,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import research.loghunter.entity.*;
|
||||
import research.loghunter.repository.*;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -32,6 +37,8 @@ public class ScanService {
|
||||
private final ScannedFileRepository scannedFileRepository;
|
||||
private final SftpService sftpService;
|
||||
private final LogParserService logParserService;
|
||||
private final EntityManager entityManager;
|
||||
private final DataSource dataSource;
|
||||
|
||||
// 진행 상황 저장 (serverId -> ScanProgress)
|
||||
private final ConcurrentHashMap<Long, ScanProgress> progressMap = new ConcurrentHashMap<>();
|
||||
@@ -241,6 +248,8 @@ public class ScanService {
|
||||
return new ScanResult(server.getId(), server.getName(), false, 0, 0, e.getMessage());
|
||||
} finally {
|
||||
progressMap.remove(server.getId());
|
||||
// DB 최적화 (삭제된 데이터 공간 회수)
|
||||
vacuumDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,6 +409,23 @@ public class ScanService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLite VACUUM 실행 (DB 최적화)
|
||||
* 삭제된 데이터가 차지하는 공간을 회수함
|
||||
*/
|
||||
private void vacuumDatabase() {
|
||||
try (Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement()) {
|
||||
log.info("Running VACUUM to optimize database...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
stmt.execute("VACUUM");
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
log.info("VACUUM completed in {}ms", elapsed);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to vacuum database: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// DTOs
|
||||
public static class ScanProgress {
|
||||
private Long serverId;
|
||||
|
||||
Reference in New Issue
Block a user