diff options
author | Satya Rohith <me@satyarohith.com> | 2022-10-10 13:05:57 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-10 13:05:57 +0530 |
commit | 4d6aed1b528efc9bdac7cce7922259f5c703ec55 (patch) | |
tree | b3c61c38c893069bcfdedc0650a51dda11c07df9 /ext/cache/sqlite.rs | |
parent | a2488ae79200abfcbad0f0f8b084a3ff8e183880 (diff) |
perf(ext/cache): set journal_mode=wal (#16231)
Diffstat (limited to 'ext/cache/sqlite.rs')
-rw-r--r-- | ext/cache/sqlite.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/cache/sqlite.rs b/ext/cache/sqlite.rs index 75aa7cc6e..caf386777 100644 --- a/ext/cache/sqlite.rs +++ b/ext/cache/sqlite.rs @@ -45,6 +45,16 @@ impl SqliteBackedCache { let connection = rusqlite::Connection::open(&path).unwrap_or_else(|_| { panic!("failed to open cache db at {}", path.display()) }); + // Enable write-ahead-logging mode. + let initial_pragmas = " + -- enable write-ahead-logging mode + PRAGMA journal_mode=WAL; + PRAGMA synchronous=NORMAL; + PRAGMA optimize; + "; + connection + .execute_batch(initial_pragmas) + .expect("failed to execute pragmas"); connection .execute( "CREATE TABLE IF NOT EXISTS cache_storage ( @@ -117,7 +127,7 @@ impl Cache for SqliteBackedCache { tokio::task::spawn_blocking(move || { let db = db.lock(); let cache_exists = db.query_row( - "SELECT count(cache_name) FROM cache_storage WHERE cache_name = ?1", + "SELECT count(id) FROM cache_storage WHERE cache_name = ?1", params![cache_name], |row| { let count: i64 = row.get(0)?; |