From 3be6fb1a809013f9915b6fc2fca015b46c4a2ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Wed, 7 Jan 2026 12:14:00 +0100 Subject: [PATCH] fix(sqlite): Add WAL checkpoints when vacuuming For some reason, the automatic WAL checkpoints don't seem to be working as expected. Since we should periodically run VACUUM operations, we might as well add checkpoints before vacuuming (so the WAL size is reset and can grow to fit the whole DB) and after (so we clean up after that). --- crates/matrix-sdk-sqlite/src/utils.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/matrix-sdk-sqlite/src/utils.rs b/crates/matrix-sdk-sqlite/src/utils.rs index d9265a77c..ce10de06e 100644 --- a/crates/matrix-sdk-sqlite/src/utils.rs +++ b/crates/matrix-sdk-sqlite/src/utils.rs @@ -187,6 +187,7 @@ pub(crate) trait SqliteAsyncConnExt { /// /// Only returns an error in tests, otherwise the error is only logged. async fn vacuum(&self) -> Result<()> { + self.wal_checkpoint().await; if let Err(error) = self.execute_batch("VACUUM").await { // Since this is an optimisation step, do not propagate the error // but log it. @@ -198,11 +199,19 @@ pub(crate) trait SqliteAsyncConnExt { return Err(error.into()); } else { trace!("VACUUM complete"); + self.wal_checkpoint().await; } Ok(()) } + async fn wal_checkpoint(&self) { + match self.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);").await { + Ok(_) => trace!("WAL checkpoint completed"), + Err(error) => error!(?error, "WAL checkpoint error"), + } + } + async fn get_db_size(&self) -> Result { let page_size = self.query_row("PRAGMA page_size;", (), |row| row.get::<_, usize>(0)).await?;