Skip to content

Commit

Permalink
refactor(dictionary): disable wal autocheckpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jan 2, 2024
1 parent 42c252c commit 7fcc5aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/dictionary/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions src/editor/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(())
}

Expand Down

0 comments on commit 7fcc5aa

Please sign in to comment.