feat(sqlite): commit WAL on startup (#684)

* fix(sqlite): increase page_size to 65536

* fix(db): implement WAL commit on startup

* revert page_size
This commit is contained in:
Kyle Sanderson 2023-03-19 13:21:02 -07:00 committed by GitHub
parent ef61331a22
commit 603828be9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,6 +34,16 @@ func (db *DB) openSQLite() error {
return errors.Wrap(err, "enable wal") return errors.Wrap(err, "enable wal")
} }
// When Autobrr does not cleanly shutdown, the WAL will still be present and not committed.
// This is a no-op if the WAL is empty, and a commit when the WAL is not to start fresh.
// When commits hit 1000, PRAGMA wal_checkpoint(PASSIVE); is invoked which tries its best
// to commit from the WAL (and can fail to commit all pending operations).
// Forcing a PRAGMA wal_checkpoint(RESTART); in the future on a "quiet period" could be
// considered.
if _, err = db.handler.Exec(`PRAGMA wal_checkpoint(TRUNCATE);`); err != nil {
return errors.Wrap(err, "commit wal")
}
// Enable foreign key checks. For historical reasons, SQLite does not check // Enable foreign key checks. For historical reasons, SQLite does not check
// foreign key constraints by default. There's some overhead on inserts to // foreign key constraints by default. There's some overhead on inserts to
// verify foreign key integrity, but it's definitely worth it. // verify foreign key integrity, but it's definitely worth it.