Problem
In lib/core/storage/local_db.dart, the local SQLite database (querya.db) initialization only executes PRAGMA foreign_keys = ON in onOpen:
onOpen: (db) async {
await db.execute('PRAGMA foreign_keys = ON');
}
By default, SQLite uses journal_mode = DELETE with a busy_timeout of 0 ms. When concurrent operations occur (e.g. background query history recording, cloud sync folder watchers, or multiple rapid app reads/writes), SQLite immediately fails with DatabaseException: SQLITE_BUSY (database is locked).
Proposed Solution
- In
LocalDb._open() (onOpen callback), configure robust concurrent PRAGMAs:
PRAGMA journal_mode = WAL; (Write-Ahead Logging allows non-blocking concurrent readers while a write occurs).
PRAGMA busy_timeout = 5000; (Gracefully retry for up to 5000ms instead of immediately failing).
PRAGMA synchronous = NORMAL; (Optimal and safe synchronization mode under WAL).
- Add unit tests in
test/core/storage/local_db_test.dart verifying that PRAGMA settings are active and concurrent reads/writes succeed without locking errors.
Problem
In
lib/core/storage/local_db.dart, the local SQLite database (querya.db) initialization only executesPRAGMA foreign_keys = ONinonOpen:By default, SQLite uses
journal_mode = DELETEwith abusy_timeoutof 0 ms. When concurrent operations occur (e.g. background query history recording, cloud sync folder watchers, or multiple rapid app reads/writes), SQLite immediately fails withDatabaseException: SQLITE_BUSY (database is locked).Proposed Solution
LocalDb._open()(onOpencallback), configure robust concurrent PRAGMAs:PRAGMA journal_mode = WAL;(Write-Ahead Logging allows non-blocking concurrent readers while a write occurs).PRAGMA busy_timeout = 5000;(Gracefully retry for up to 5000ms instead of immediately failing).PRAGMA synchronous = NORMAL;(Optimal and safe synchronization mode under WAL).test/core/storage/local_db_test.dartverifying that PRAGMA settings are active and concurrent reads/writes succeed without locking errors.