1
1
use std:: path:: PathBuf ;
2
2
3
3
use db:: { DbInstrumentation , QUERY_HISTOGRAM } ;
4
+ use diesel:: connection:: SimpleConnection ;
4
5
use diesel:: r2d2:: Pool ;
5
6
use diesel:: sqlite:: Sqlite ;
6
7
use diesel:: { r2d2:: ConnectionManager , SqliteConnection } ;
@@ -114,6 +115,19 @@ impl<R: Handler + Clone> From<AdminOnlyRoute<R>> for Vec<Route> {
114
115
struct AdminToken ( String ) ;
115
116
struct APWorldPath ( PathBuf ) ;
116
117
118
+ #[ derive( Debug ) ]
119
+ struct SqliteCustomizer ;
120
+
121
+ impl diesel:: r2d2:: CustomizeConnection < SqliteConnection , diesel:: r2d2:: Error > for SqliteCustomizer {
122
+ fn on_acquire ( & self , conn : & mut SqliteConnection ) -> Result < ( ) , diesel:: r2d2:: Error > {
123
+ conn. batch_execute (
124
+ "PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL; PRAGMA busy_timeout = 1000;" ,
125
+ )
126
+ . map_err ( diesel:: r2d2:: Error :: QueryError ) ?;
127
+ Ok ( ( ) )
128
+ }
129
+ }
130
+
117
131
#[ rocket:: main]
118
132
async fn main ( ) -> anyhow:: Result < ( ) > {
119
133
dotenv ( ) . ok ( ) ;
@@ -127,7 +141,10 @@ async fn main() -> anyhow::Result<()> {
127
141
. expect ( "Failed to set diesel instrumentation" ) ;
128
142
129
143
let manager = ConnectionManager :: < SqliteConnection > :: new ( db_url) ;
130
- let db_pool = Pool :: new ( manager) . expect ( "Failed to create database pool, aborting" ) ;
144
+ let db_pool = Pool :: builder ( )
145
+ . connection_customizer ( Box :: new ( SqliteCustomizer ) )
146
+ . build ( manager)
147
+ . expect ( "Failed to create database pool, aborting" ) ;
131
148
{
132
149
let mut connection = db_pool
133
150
. get ( )
0 commit comments