perf: SQLite NORMAL mode on fs vault connections
parent
fc27936acc
commit
7ce7615b3a
|
@ -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 {
|
||||
path: PathBuf,
|
||||
pool: r2d2::Pool<ConnectionManager<SqliteConnection>>,
|
||||
|
@ -76,7 +95,9 @@ impl FsStore {
|
|||
.to_str()
|
||||
.unwrap(),
|
||||
);
|
||||
let pool = r2d2::Pool::builder().build(manager)?;
|
||||
let pool = r2d2::Pool::builder()
|
||||
.connection_customizer(Box::new(ConnectionOptions {}))
|
||||
.build(manager)?;
|
||||
let connection = pool.get()?;
|
||||
|
||||
// while diesel doesn't support multiple embedded migrations...
|
||||
|
|
Loading…
Reference in New Issue