Use transaction when loading logs.

This commit is contained in:
Greyson Parrelli
2026-03-10 16:53:21 +00:00
committed by Cody Henthorne
parent c5de7581ee
commit cee33a23ac

View File

@@ -61,7 +61,8 @@ public class SubmitDebugLogViewModel extends ViewModel {
Log.blockUntilAllWritesFinished();
stopwatch.split("flush");
LogDatabase.getInstance(AppDependencies.getApplication()).logs().trimToSize();
LogDatabase logDatabase = LogDatabase.getInstance(AppDependencies.getApplication());
logDatabase.logs().trimToSize();
stopwatch.split("trim-old");
if (!emitter.isDisposed()) {
@@ -69,8 +70,9 @@ public class SubmitDebugLogViewModel extends ViewModel {
}
List<String> currentChunk = new ArrayList<>();
try (LogDatabase.LogTable.CursorReader logReader = (LogDatabase.LogTable.CursorReader) LogDatabase.getInstance(AppDependencies.getApplication()).logs().getAllBeforeTime(firstViewTime)) {
logDatabase.getReadableDatabase().beginTransactionNonExclusive();
try {
try (LogDatabase.LogTable.CursorReader logReader = (LogDatabase.LogTable.CursorReader) logDatabase.logs().getAllBeforeTime(firstViewTime)) {
stopwatch.split("initial-query");
int count = 0;
@@ -99,6 +101,10 @@ public class SubmitDebugLogViewModel extends ViewModel {
stopwatch.split("lines");
stopwatch.stop(TAG);
}
logDatabase.getReadableDatabase().setTransactionSuccessful();
} finally {
logDatabase.getReadableDatabase().endTransaction();
}
} catch (Exception e) {
if (!emitter.isDisposed()) {
Log.e(TAG, "Error loading log lines", e);