Skip to content

Commit

Permalink
Merge branch 'master' into code-auto-format
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszLitwiniuk authored Jan 9, 2025
2 parents 7ac11f2 + 1955453 commit 9b83f30
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ private BacktraceDatabaseContext(Context context, String path, int retryNumber,
* Setup cache
*/
private void setupBatch() {
if (this._retryNumber == 0) {
if (this._retryNumber <= 0) {
throw new IllegalArgumentException("Retry number must be greater than 0!");
}

for (int i = 0; i < _retryNumber; i++) {
this.batchRetry.put(i, new ArrayList<BacktraceDatabaseRecord>());
this.batchRetry.put(i, new ArrayList<>());
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public BacktraceDatabaseRecord add(BacktraceDatabaseRecord backtraceDatabaseReco
}
backtraceDatabaseRecord.locked = true;
this.totalSize += backtraceDatabaseRecord.getSize();
this.batchRetry.get(0).add(backtraceDatabaseRecord); // TODO: null
this.addToFirstBatch(backtraceDatabaseRecord);
this.totalRecords++;
return backtraceDatabaseRecord;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ public boolean removeOldestRecord() {
private void incrementBatches() {
for (int i = this._retryNumber - 2; i >= 0; i--) {
List<BacktraceDatabaseRecord> currentBatch = this.batchRetry.get(i);
batchRetry.put(i, new ArrayList<BacktraceDatabaseRecord>());
batchRetry.put(i, new ArrayList<>());
batchRetry.put(i + 1, currentBatch);
}
}
Expand Down Expand Up @@ -344,7 +344,6 @@ private BacktraceDatabaseRecord getLastRecord() {
return getRecordFromCache(true);
}


/**
* Get record in in-cache BacktraceDatabase
*
Expand Down Expand Up @@ -372,4 +371,21 @@ private BacktraceDatabaseRecord getRecordFromCache(boolean reverse) {
}
return null;
}

private void addToFirstBatch(BacktraceDatabaseRecord backtraceDatabaseRecord) {
final int firstBatch = 0;

if (this.batchRetry.isEmpty()) {
this.batchRetry.put(firstBatch, new ArrayList<>());
}

List<BacktraceDatabaseRecord> batch = this.batchRetry.get(firstBatch);

if (batch == null) {
batch = new ArrayList<>();
this.batchRetry.put(firstBatch, batch);
}

batch.add(backtraceDatabaseRecord);
}
}

0 comments on commit 9b83f30

Please sign in to comment.