Fix Bug #3320: Reduce I/O pressure on SQLite DB Operations (#3334)

* Reduce I/O pressure on SQLite DB Operations
* Update allow.txt - add autocheckpoint
This commit is contained in:
abraunegg 2025-06-14 12:18:02 +10:00 committed by GitHub
commit 95938807b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View file

@ -36,6 +36,7 @@ AThings
attrnamespace
aufxw
aur
autocheckpoint
autoclean
automake
autoprocess

View file

@ -317,6 +317,8 @@ final class ItemDatabase {
// Set the journal mode for databases associated with the current connection
// https://www.sqlite.org/pragma.html#pragma_journal_mode
db.exec("PRAGMA journal_mode = WAL;");
// Only checkpoint if WAL grows past a certain size
db.exec("PRAGMA wal_autocheckpoint = 1000;");
// Automatic indexing is enabled by default as of version 3.7.17
// https://www.sqlite.org/pragma.html#pragma_automatic_index
// PRAGMA automatic_index = boolean;
@ -1214,8 +1216,8 @@ final class ItemDatabase {
}
}
// Ensure there are no pending operations by performing a checkpoint
db.exec("PRAGMA wal_checkpoint(TRUNCATE);");
// Ensure there are no pending operations by performing a PASSIVE checkpoint
db.exec("PRAGMA wal_checkpoint(PASSIVE);");
// Prepare and execute VACUUM statement
Statement stmt = db.prepare("VACUUM;");

View file

@ -1177,7 +1177,7 @@ int main(string[] cliArgs) {
// Write WAL and SHM data to file for this loop and release memory used by in-memory processing
if (debugLogging) {addLogEntry("Merge contents of WAL and SHM files into main database file", ["debug"]);}
itemDB.performCheckpoint("TRUNCATE");
itemDB.performCheckpoint("PASSIVE");
} else {
// Not online
addLogEntry("Microsoft OneDrive service is not reachable at this time. Will re-try on next sync attempt.");