diff --git a/patchfinder/src/main/java/db/DatabaseHelper.java b/patchfinder/src/main/java/db/DatabaseHelper.java index d84ce0390..ebd38e7e7 100644 --- a/patchfinder/src/main/java/db/DatabaseHelper.java +++ b/patchfinder/src/main/java/db/DatabaseHelper.java @@ -412,21 +412,21 @@ public List getCves(int cveLimit) { return cves; } - public void insertFixes(List fixes) { - int existingInserts = 0; + public int[] insertFixes(List fixes) { int failedInserts = 0; + int existingInserts = 0; for (Fix fix : fixes) { try { final int result = this.insertFix(fix); - // Result of operation, 0 for OK, 1 for error, 2 for already exists + // Result of operation, 0 for OK, 1 for failed, 2 for already exists switch (result) { - case 2: - existingInserts++; - break; case 1: failedInserts++; break; + case 2: + existingInserts++; + break; default: break; } @@ -436,11 +436,7 @@ public void insertFixes(List fixes) { } } - logger.info("Successfully inserted {} fixes into the database ({} failed, {} already existed)", - fixes.size() - failedInserts - existingInserts, - failedInserts, - existingInserts - ); + return new int[] {failedInserts, existingInserts}; } /** diff --git a/patchfinder/src/main/java/fixes/FixFinderThread.java b/patchfinder/src/main/java/fixes/FixFinderThread.java index 81d802d5a..145bbc517 100644 --- a/patchfinder/src/main/java/fixes/FixFinderThread.java +++ b/patchfinder/src/main/java/fixes/FixFinderThread.java @@ -97,6 +97,10 @@ public void run() { futures.add(future); } + int totalFixes = 0; + int totalFailedInserts = 0; + int totalExistingInserts = 0; + // Wait for all futures to complete and collect their results for (CompletableFuture> future : futures) { try { @@ -104,7 +108,13 @@ public void run() { final List fixes = future.get(); // Ensure no null values are allowed past here if(fixes != null) { - FixFinder.getDatabaseHelper().insertFixes(fixes); + // Insert fixes as jobs complete + final int[] results = FixFinder.getDatabaseHelper().insertFixes(fixes); + // Collect insert results + totalFailedInserts += results[0]; + totalExistingInserts += results[1]; + totalFixes += fixes.size(); + logger.info("{} fixes found for CVE: {}", fixes.size(), cveId); } else logger.warn("Future returned null"); @@ -113,6 +123,13 @@ public void run() { e.printStackTrace(); } } + + // Final stats logging for thread + logger.info("Successfully inserted {} fixes into the database ({} failed, {} already existed)", + totalFixes - (totalFailedInserts + totalExistingInserts), + totalFailedInserts, + totalExistingInserts + ); } }