Skip to content

Commit

Permalink
Logging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-mulligan committed Nov 2, 2023
1 parent 7b1726f commit 0aec5f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
18 changes: 7 additions & 11 deletions patchfinder/src/main/java/db/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,21 +412,21 @@ public List<String> getCves(int cveLimit) {
return cves;
}

public void insertFixes(List<Fix> fixes) {
int existingInserts = 0;
public int[] insertFixes(List<Fix> 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;
}
Expand All @@ -436,11 +436,7 @@ public void insertFixes(List<Fix> fixes) {
}
}

logger.info("Successfully inserted {} fixes into the database ({} failed, {} already existed)",
fixes.size() - failedInserts - existingInserts,
failedInserts,
existingInserts
);
return new int[] {failedInserts, existingInserts};
}

/**
Expand Down
19 changes: 18 additions & 1 deletion patchfinder/src/main/java/fixes/FixFinderThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,24 @@ 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<List<Fix>> future : futures) {
try {
// Get results of the future
final List<Fix> 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");
Expand All @@ -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
);
}

}

0 comments on commit 0aec5f7

Please sign in to comment.