Skip to content

Commit 5d17376

Browse files
committed
Enable WAL journal mode to get faster writes
1 parent 2c48aa7 commit 5d17376

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/src/db/database.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Future<Database> openAppDatabase(DatabaseFactory dbFactory, String path) {
7272
onConfigure: (db) async {
7373
final version = await _getDatabaseVersion(db);
7474
_logger.info('SQLite version: $version');
75+
if (version != null && version >= 307000) {
76+
_logger.info('Enabling WAL journal mode');
77+
await db.rawQuery('PRAGMA journal_mode=WAL');
78+
}
7579
},
7680
onOpen: (db) async {
7781
await Future.wait([

lib/src/log.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,17 @@ class AppLogService {
7070
_logs.put(record);
7171

7272
// Persist to database asynchronously (fire-and-forget).
73+
// Deferred via Future() to avoid re-entrant logging: ref.read() can synchronously mount
74+
// providers, which triggers ProviderLogger.didAddProvider → _logger.info() → re-entrant
75+
// Logger._publish while already dispatching, causing a StateError.
7376
// The try-catch guards against ref being invalid (e.g. disposed ProviderScope in tests).
74-
try {
75-
ref
76-
.read(appLogStorageProvider.future)
77-
.then((storage) => storage.save(AppLogEntry.fromLogRecord(record)), onError: (_) {});
78-
} catch (_) {}
77+
Future(() {
78+
try {
79+
ref
80+
.read(appLogStorageProvider.future)
81+
.then((storage) => storage.save(AppLogEntry.fromLogRecord(record)), onError: (_) {});
82+
} catch (_) {}
83+
});
7984
});
8085
}
8186

0 commit comments

Comments
 (0)