Skip to content

Commit

Permalink
fix: use truncate instead delete for db table clean-up (#581)
Browse files Browse the repository at this point in the history
Relates: MSEARCH-744
(cherry picked from commit 07dfc77)
  • Loading branch information
psmagin committed May 14, 2024
1 parent 65c3d80 commit 3299255
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ConsortiumInstanceRepository {

private static final String SELECT_BY_ID_SQL = "SELECT * FROM %s WHERE instance_id IN (%s)";
private static final String DELETE_BY_TENANT_AND_ID_SQL = "DELETE FROM %s WHERE tenant_id = ? AND instance_id = ?;";
private static final String DELETE_ALL_SQL = "DELETE FROM %s;";
private static final String DELETE_ALL_SQL = "TRUNCATE TABLE %s;";
private static final String UPSERT_SQL = """
INSERT INTO %s (tenant_id, instance_id, json, created_date, updated_date)
VALUES (?, ?, ?::json, ?, ?)
Expand Down Expand Up @@ -114,7 +114,8 @@ public List<ConsortiumItem> fetchItems(ConsortiumSearchQueryBuilder searchQueryB
}

public void deleteAll() {
jdbcTemplate.update(DELETE_ALL_SQL.formatted(getTableName()));
log.debug("deleteAll::consortium instances");
jdbcTemplate.execute(DELETE_ALL_SQL.formatted(getTableName()));
}

private ConsortiumInstance toConsortiumInstance(ResultSet rs) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public List<ResourceEvent> deleteInstances(List<ResourceEvent> instanceEvents) {
}

public void deleteAll() {
log.info("Truncate consortium instances table");
consortiumTenantExecutor.run(repository::deleteAll);
}

Expand Down

0 comments on commit 3299255

Please sign in to comment.