perf: SQLite NORMAL mode on fs vault connections
This commit is contained in:
parent
fc27936acc
commit
7ce7615b3a
1 changed files with 22 additions and 1 deletions
|
@ -61,6 +61,25 @@ impl Drop for PragmaSynchronousGuard<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ConnectionOptions;
|
||||||
|
|
||||||
|
impl ConnectionOptions {
|
||||||
|
pub fn apply(&self, conn: &SqliteConnection) -> diesel::QueryResult<()> {
|
||||||
|
debug!(r#"Setting "synchronous" to NORMAL"#);
|
||||||
|
conn.execute("PRAGMA synchronous = NORMAL;")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl diesel::r2d2::CustomizeConnection<SqliteConnection, diesel::r2d2::Error>
|
||||||
|
for ConnectionOptions
|
||||||
|
{
|
||||||
|
fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), diesel::r2d2::Error> {
|
||||||
|
self.apply(conn).map_err(diesel::r2d2::Error::QueryError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FsStore {
|
pub struct FsStore {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
pool: r2d2::Pool<ConnectionManager<SqliteConnection>>,
|
pool: r2d2::Pool<ConnectionManager<SqliteConnection>>,
|
||||||
|
@ -76,7 +95,9 @@ impl FsStore {
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
let pool = r2d2::Pool::builder().build(manager)?;
|
let pool = r2d2::Pool::builder()
|
||||||
|
.connection_customizer(Box::new(ConnectionOptions {}))
|
||||||
|
.build(manager)?;
|
||||||
let connection = pool.get()?;
|
let connection = pool.get()?;
|
||||||
|
|
||||||
// while diesel doesn't support multiple embedded migrations...
|
// while diesel doesn't support multiple embedded migrations...
|
||||||
|
|
Loading…
Reference in a new issue