mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
feat(sql): truncate WAL on stop_io()
This commit is contained in:
@@ -423,6 +423,9 @@ impl Context {
|
||||
/// Stops the IO scheduler.
|
||||
pub async fn stop_io(&self) {
|
||||
self.scheduler.stop(self).await;
|
||||
if let Err(err) = self.sql.checkpoint(self).await {
|
||||
error!(self, "Failed to checkpoint the database: {err:#}.");
|
||||
}
|
||||
}
|
||||
|
||||
/// Restarts the IO scheduler if it was running before
|
||||
|
||||
17
src/sql.rs
17
src/sql.rs
@@ -131,6 +131,23 @@ impl Sql {
|
||||
// drop closes the connection
|
||||
}
|
||||
|
||||
/// Flushes the WAL file.
|
||||
pub(crate) async fn checkpoint(&self, context: &Context) -> Result<()> {
|
||||
let busy = self
|
||||
.call_write(move |conn| {
|
||||
let busy = conn.query_row("PRAGMA wal_checkpoint(TRUNCATE)", (), |row| {
|
||||
let busy: bool = row.get(0)?;
|
||||
Ok(busy)
|
||||
})?;
|
||||
Ok(busy)
|
||||
})
|
||||
.await?;
|
||||
if busy {
|
||||
warn!(context, "Failed to checkpoint WAL");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Imports the database from a separate file with the given passphrase.
|
||||
pub(crate) async fn import(&self, path: &Path, passphrase: String) -> Result<()> {
|
||||
let path_str = path
|
||||
|
||||
Reference in New Issue
Block a user