Skip to content

Commit b16130b

Browse files
Fix TestCaseRepository deleteChildren N-squared nested loop and double-delete in deleteAllTestCaseResults
1 parent aa4ae7a commit b16130b

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import java.util.Map;
4141
import java.util.Set;
4242
import java.util.UUID;
43-
import java.util.concurrent.ExecutorService;
44-
import java.util.concurrent.Executors;
4543
import java.util.function.Function;
4644
import java.util.stream.Collectors;
4745
import lombok.SneakyThrows;
@@ -120,9 +118,6 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
120118
private static final String PATCH_FIELDS =
121119
"owners,entityLink,testSuite,testSuites,testDefinition,computePassedFailedRowCount,useDynamicAssertion,dimensionColumns,topDimensions";
122120
public static final String FAILED_ROWS_SAMPLE_EXTENSION = "testCase.failedRowsSample";
123-
private final ExecutorService asyncExecutor =
124-
Executors.newFixedThreadPool(
125-
1, java.lang.Thread.ofPlatform().name("om-test-case-async").factory());
126121

127122
public TestCaseRepository() {
128123
super(
@@ -896,18 +891,12 @@ private void updateLogicalTestSuite(UUID testSuiteId) {
896891
protected void deleteChildren(
897892
List<CollectionDAO.EntityRelationshipRecord> children, boolean hardDelete, String updatedBy) {
898893
if (hardDelete) {
899-
for (CollectionDAO.EntityRelationshipRecord entityRelationshipRecord : children) {
900-
LOG.info(
901-
"Recursively {} deleting {} {}",
902-
hardDelete ? "hard" : "soft",
903-
entityRelationshipRecord.getType(),
904-
entityRelationshipRecord.getId());
905-
TestCaseResolutionStatusRepository testCaseResolutionStatusRepository =
906-
(TestCaseResolutionStatusRepository)
907-
Entity.getEntityTimeSeriesRepository(Entity.TEST_CASE_RESOLUTION_STATUS);
908-
for (CollectionDAO.EntityRelationshipRecord child : children) {
909-
testCaseResolutionStatusRepository.deleteById(child.getId(), hardDelete);
910-
}
894+
TestCaseResolutionStatusRepository testCaseResolutionStatusRepository =
895+
(TestCaseResolutionStatusRepository)
896+
Entity.getEntityTimeSeriesRepository(Entity.TEST_CASE_RESOLUTION_STATUS);
897+
for (CollectionDAO.EntityRelationshipRecord child : children) {
898+
LOG.info("Hard deleting {} {}", child.getType(), child.getId());
899+
testCaseResolutionStatusRepository.deleteById(child.getId(), hardDelete);
911900
}
912901
}
913902
}
@@ -921,14 +910,6 @@ private void deleteAllTestCaseResults(String fqn) {
921910
TestCaseResultRepository testCaseResultRepository =
922911
(TestCaseResultRepository) Entity.getEntityTimeSeriesRepository(TEST_CASE_RESULT);
923912
testCaseResultRepository.deleteAllTestCaseResults(fqn);
924-
asyncExecutor.submit(
925-
() -> {
926-
try {
927-
testCaseResultRepository.deleteAllTestCaseResults(fqn);
928-
} catch (Exception e) {
929-
LOG.error("Error deleting test case results for test case {}", fqn, e);
930-
}
931-
});
932913
}
933914

934915
@SneakyThrows

0 commit comments

Comments
 (0)