261123_01_FIX: 리스트 업로드 DB 중복 검사 쿼리 인덱스 활용 및 타임아웃(5분) 적용, 검증 실패 시 원인 예외 보존 #48
@@ -9,13 +9,17 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapperResultSetExtractor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ListUploadJdbcSupport {
|
||||
private static final int DB_DUPLICATE_QUERY_TIMEOUT_SECONDS = 300;
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void deleteTemp(String listUploadLogId) {
|
||||
@@ -115,24 +119,31 @@ public class ListUploadJdbcSupport {
|
||||
and t.prjct_idx = ?
|
||||
and t.normalized_val is not null
|
||||
and t.specific_type in (?, ?)
|
||||
and lower(trim(i.list_item_val)) = t.normalized_val
|
||||
and i.list_item_val = t.normalized_val
|
||||
and (? = false or i.sid <> t.sid)
|
||||
order by t.row_no, t.list_hder_id
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(
|
||||
sql,
|
||||
(rs, rowNum) -> new DuplicateHit(
|
||||
con -> {
|
||||
PreparedStatement ps = con.prepareStatement(sql);
|
||||
// Fail fast and let the driver KILL QUERY on the server instead of waiting indefinitely.
|
||||
ps.setQueryTimeout(DB_DUPLICATE_QUERY_TIMEOUT_SECONDS);
|
||||
return ps;
|
||||
},
|
||||
new ArgumentPreparedStatementSetter(new Object[] {
|
||||
listUploadLogId,
|
||||
prjctIdx,
|
||||
ListHeaderTypeSpecific.EMAIL.getCode(),
|
||||
ListHeaderTypeSpecific.TEL_NUM.getCode(),
|
||||
excludeSameSid
|
||||
}),
|
||||
new RowMapperResultSetExtractor<>((rs, rowNum) -> new DuplicateHit(
|
||||
rs.getInt("row_no"),
|
||||
rs.getString("sid"),
|
||||
rs.getInt("list_hder_id"),
|
||||
rs.getString("raw_val")
|
||||
),
|
||||
listUploadLogId,
|
||||
prjctIdx,
|
||||
ListHeaderTypeSpecific.EMAIL.getCode(),
|
||||
ListHeaderTypeSpecific.TEL_NUM.getCode(),
|
||||
excludeSameSid
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -428,6 +428,7 @@ public class ListUploadService {
|
||||
if (request.uploadMode() == null) {
|
||||
throw BusinessException.badRequest("ASYNC_UPLOAD_MODE_REQUIRED", "Upload mode is required");
|
||||
}
|
||||
RuntimeException primaryFailure = null;
|
||||
try {
|
||||
checkCancelled.run();
|
||||
var errors = new ArrayList<ListUploadErrorDto>();
|
||||
@@ -459,11 +460,18 @@ public class ListUploadService {
|
||||
return new PreparedUpload(validation.totalCount(), Set.copyOf(validation.uploadedSids()),
|
||||
List.copyOf(headers), Map.copyOf(companies), createHeaders, List.copyOf(validation.errors()));
|
||||
} catch (RuntimeException failure) {
|
||||
primaryFailure = failure;
|
||||
checkCancelled.run();
|
||||
throw failure;
|
||||
} finally {
|
||||
// All validation staging is in this transaction; a restart also rolls it back.
|
||||
listUploadJdbcSupport.deleteTemp(logId);
|
||||
try {
|
||||
listUploadJdbcSupport.deleteTemp(logId);
|
||||
} catch (RuntimeException cleanupFailure) {
|
||||
// Keep the original failure (e.g. a broken connection) instead of masking it with the cleanup failure.
|
||||
if (primaryFailure == null) throw cleanupFailure;
|
||||
primaryFailure.addSuppressed(cleanupFailure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user