Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(#21): bulk api delete 오류 수정 #39

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/kimandhong/oxox/bulk/BulkRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,23 @@ public void deleteReactions() {

public void deleteComments() {
String[] sqls = {
"SET FOREIGN_KEY_CHECKS = 0",
"DELETE FROM reactions",
"DELETE FROM comments"
"DELETE FROM comments",
"SET FOREIGN_KEY_CHECKS = 1"
};

jdbcTemplate.batchUpdate(sqls);
}

public void deletePosts() {
String[] sqls = {
"SET FOREIGN_KEY_CHECKS = 0",
"DELETE FROM votes",
"DELETE FROM reactions",
"DELETE FROM comments",
"DELETE FROM posts"
"DELETE FROM posts",
"SET FOREIGN_KEY_CHECKS = 1"
};

jdbcTemplate.batchUpdate(sqls);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경된 코드의 문제 및 개선 제안:

  1. deleteReactions() 메서드:

    • FOREIGN KEY CHECK를 0으로 설정하고 유지하지 않은 채로 reactions 테이블에서만 데이터를 삭제할 수 있습니다.
    • 마지막에 FOREIGN KEY CHECKS를 1로 설정하는 것이 좋습니다.
  2. deleteComments() 메서드:

    • 현재 코드에 오류나 변경 사항은 없어 보입니다.
  3. deletePosts() 메서드:

    • FOREIGN KEY CHECK를 0으로 설정하고 유지하지 않은 채로 votes, reactions, commentsposts 테이블에서 데이터를 삭제합니다.
    • 마지막에 FOREIGN KEY CHECKS를 1로 설정해야 합니다.

개선 제안:

  • 각 메서드에서 FOREIGN KEY CHECKS를 활성화/비활성화하여 일관성을 유지하도록 합니다.
  • 각 SQL 명령문 실행 후 적절한 로깅 또는 예외 처리를 추가하여 데이터의 손실을 방지할 수 있습니다.
  • 코드 주석을 추가하여 각 단계의 의도를 설명하면 이해하기 쉬울 것입니다.

Expand Down