Skip to content

Commit

Permalink
Prettier formatting, extra safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessimone committed Jun 7, 2021
1 parent 8051d55 commit 44c7924
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions nebula-logger/main/log-management/classes/LogBatchPurger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ global with sharing class LogBatchPurger implements Database.Batchable<SObject>,
this.hardDelete(safeToDeleteRecords);
}


if (!this.recordsToDelete.isEmpty() && Limits.getLimitQueueableJobs() > Limits.getQueueableJobs()) {
System.enqueueJob(this);
}
Expand All @@ -58,9 +57,14 @@ global with sharing class LogBatchPurger implements Database.Batchable<SObject>,
}

private void hardDelete(List<SObject> records) {
DELETED_COUNT += records.size();
delete records;
Database.emptyRecycleBin(records);
// normally this would be an anti-pattern since most DML operations
// are a no-op with an empty list - but emptyRecycleBin throws
// for empty lists!
if (!records.isEmpty()) {
DELETED_COUNT += records.size();
delete records;
Database.emptyRecycleBin(records);
}
}
}

Expand Down Expand Up @@ -88,15 +92,13 @@ global with sharing class LogBatchPurger implements Database.Batchable<SObject>,
throw new LogBatchPurgerException('User does not have access to delete logs');
}


try {
// Delete the child log entries first
List<LogEntry__c> logEntriesToDelete = [SELECT Id FROM LogEntry__c WHERE Log__c IN :logsToDelete];
if (this.isSystemDebuggingEnabled) {
Logger.setParentLogTransactionId(this.originalTransactionId);
Logger.info(new LogMessage('Starting deletion of {0} records', logsToDelete.size()));
Logger.info(new LogMessage('Starting deletion of {0} logs and {1} log entries', logsToDelete.size(), logEntriesToDelete.size()));
}

// Delete the child log entries first
List<LogEntry__c> logEntriesToDelete = [SELECT Id FROM LogEntry__c WHERE Log__c IN :logsToDelete];
new LogDeleter(logEntriesToDelete).process();

// Now delete the parent logs
Expand Down

0 comments on commit 44c7924

Please sign in to comment.