From 7fcc5aa6d1c5d64239d74cbfdbb5c5e70b498173 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Fri, 3 Feb 2023 22:34:55 +0900 Subject: [PATCH] refactor(dictionary): disable wal autocheckpoint --- src/dictionary/sqlite.rs | 1 + src/editor/estimate.rs | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/dictionary/sqlite.rs b/src/dictionary/sqlite.rs index 29965261c..0fcb4eb63 100644 --- a/src/dictionary/sqlite.rs +++ b/src/dictionary/sqlite.rs @@ -84,6 +84,7 @@ impl SqliteDictionary { fn initialize_tables(conn: &Connection) -> Result<(), SqliteDictionaryError> { conn.pragma_update(None, "journal_mode", "WAL")?; conn.pragma_update(None, "synchronous", "NORMAL")?; + conn.pragma_update(None, "wal_autocheckpoint", 0)?; conn.execute( "CREATE TABLE IF NOT EXISTS dictionary_v1 ( syllables BLOB NOT NULL, diff --git a/src/editor/estimate.rs b/src/editor/estimate.rs index 958eaa5b8..8bae0b6de 100644 --- a/src/editor/estimate.rs +++ b/src/editor/estimate.rs @@ -62,6 +62,7 @@ impl SqliteUserFreqEstimate { fn initialize_tables(conn: &Connection) -> Result<(), EstimateError> { conn.pragma_update(None, "journal_mode", "WAL")?; conn.pragma_update(None, "synchronous", "NORMAL")?; + conn.pragma_update(None, "wal_autocheckpoint", 0)?; conn.execute( "CREATE TABLE IF NOT EXISTS config_v1 ( id INTEGER PRIMARY KEY, @@ -84,14 +85,11 @@ const MAX_USER_FREQ: u32 = 99999999; impl UserFreqEstimate for SqliteUserFreqEstimate { fn tick(&mut self) -> Result<(), EstimateError> { - // TODO debounce write - self.conn - .execute("UPDATE config_v1 SET value = value + 1 WHERE id = 0", [])?; - self.lifetime = - self.conn - .query_row("SELECT value FROM config_v1 WHERE id = 0", [], |row| { - row.get(0) - })?; + self.lifetime = self.conn.query_row( + "UPDATE config_v1 SET value = value + 1 WHERE id = 0 RETURNING value", + [], + |row| row.get(0), + )?; Ok(()) }