From 0485c55718a5f8161507e5fdb799e43c503b263a Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Fri, 18 Sep 2020 19:41:41 +0300 Subject: [PATCH] sql: create new accounts in one transaction This prevents SQLite from synchronizing to disk after each statement, saving time on high latency HDDs. --- src/sql.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sql.rs b/src/sql.rs index 81e4a9807..b9f5f25c0 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -713,8 +713,9 @@ async fn open( "First time init: creating tables in {:?}.", dbfile.as_ref(), ); - sql.with_conn(move |conn| { - conn.execute_batch( + sql.with_conn(move |mut conn| { + let tx = conn.transaction()?; + tx.execute_batch( r#" CREATE TABLE config (id INTEGER PRIMARY KEY, keyname TEXT, value TEXT); CREATE INDEX config_index1 ON config (keyname); @@ -899,6 +900,7 @@ CREATE TABLE devmsglabels ( CREATE INDEX devmsglabels_index1 ON devmsglabels (label); "#, )?; + tx.commit()?; Ok(()) }) .await?;