Skip to content

Commit

Permalink
sqlite: set journal size to 32 MB
Browse files Browse the repository at this point in the history
The default is unlimited.
  • Loading branch information
jasonish committed Jun 24, 2024
1 parent a3b088c commit 5f776fc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/sqlite/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ pub(crate) async fn open_connection(

let options = sqlite_options().filename(path).create_if_missing(create);

SqliteConnection::connect_with(&options).await
let mut conn = SqliteConnection::connect_with(&options).await?;

after_connect(&mut conn).await?;

Ok(conn)
}

pub(crate) async fn open_pool(
Expand All @@ -74,7 +78,8 @@ pub(crate) async fn open_pool(

let pool = SqlitePoolOptions::new()
.min_connections(4)
.max_connections(12);
.max_connections(12)
.after_connect(|conn, _meta| Box::pin(async move { after_connect(conn).await }));

let options = sqlite_options()
.filename(path)
Expand All @@ -84,6 +89,14 @@ pub(crate) async fn open_pool(
pool.connect_with(options).await
}

async fn after_connect(conn: &mut SqliteConnection) -> Result<(), sqlx::Error> {
let n: u64 = sqlx::query_scalar("PRAGMA journal_size_limit = 32000000")
.fetch_one(&mut *conn)
.await?;
debug!("PRAGMA journal_size_limit returned {}", n);
Ok(())
}

pub(crate) async fn init_event_db(conn: &mut SqliteConnection) -> anyhow::Result<()> {
let fresh_install = !has_table(&mut *conn, "events").await?;

Expand Down

0 comments on commit 5f776fc

Please sign in to comment.