diff --git a/CHANGELOG.md b/CHANGELOG.md index c901cd13446..d782495bba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,12 @@ - Added `blocks: Vec` to `ffi::MozAdsRequestOptions`, `AdsClient::request*_ads`, `MARSClient::fetch_ads`, `mars::AdRequest`, and `mars::AdRequest::try_new`. This is serialized and passed to MARS so that it can remove blocks server-side. +### sql_support + +- All databases are initialized with `PRAGMA auto_vacuum=incremental`. + This avoids having to do a full vacuum on the first `sql_support::run_maintenance` call. + (https://bugzilla.mozilla.org/show_bug.cgi?id=2064759) + # v156.0 (_2026-08-27_) ## ✨ What's Changed ✨ diff --git a/components/support/sql/src/open_database.rs b/components/support/sql/src/open_database.rs index ec715c16337..ca39fe4b8c8 100644 --- a/components/support/sql/src/open_database.rs +++ b/components/support/sql/src/open_database.rs @@ -154,6 +154,10 @@ fn do_open_database_with_flags>( if open_flags.contains(OpenFlags::SQLITE_OPEN_READ_WRITE) { let mut write_schema_version = true; + if db_empty { + // Need to run this before starting a transaction, since it executes VACUUM. + init_new_database(&conn)?; + } let tx = conn.transaction_with_behavior(TransactionBehavior::Immediate)?; if db_empty { debug!("{}: initializing new database", CI::NAME); @@ -204,6 +208,22 @@ pub fn open_memory_database_with_flags( open_database_with_flags(":memory:", flags, conn_initializer) } +fn init_new_database(conn: &Connection) -> Result<()> { + // Enable incremental auto-vacuum. This stores some additional data to enable auto-vacuum, + // but requires an explicit `PRAGMA incremental_vacuum` to be run rather than auto-vacuuming + // after each transaction. The `run_maintenance()` function performs an auto-vacuum. + // + // This is generally the best setting for components. Even if you're not calling + // `run_maintenance()` now, it's worth it to collect the data to avoid needing a full vacuum + // when you do. + conn.execute_one("PRAGMA auto_vacuum=incremental")?; + // Also call `VACUUM` to ensure the previous PRAGMA takes effect. + // This is not needed for a fresh database with 0 tables, which is probably what we have now. + // However, VACUUM will be a no-op in that case anyways. + conn.execute_one("VACUUM")?; + Ok(()) +} + // Attempt to handle failure when opening the database. // // Returns: