1
- use std:: { path:: Path , sync:: Arc } ;
1
+ use std:: { path:: Path , sync:: Arc , time :: Duration } ;
2
2
3
3
use anyhow:: anyhow;
4
4
pub use attachment:: {
@@ -21,7 +21,11 @@ pub use pages::{PageDAO, PageSectionDAO};
21
21
pub use provided_repositories:: ProvidedRepositoryDAO ;
22
22
pub use repositories:: RepositoryDAO ;
23
23
pub use server_setting:: ServerSettingDAO ;
24
- use sqlx:: { query, query_scalar, sqlite:: SqliteQueryResult , Pool , Sqlite , SqlitePool } ;
24
+ use sqlx:: {
25
+ query, query_scalar,
26
+ sqlite:: { SqlitePoolOptions , SqliteQueryResult } ,
27
+ Pool , Sqlite , SqlitePool ,
28
+ } ;
25
29
pub use threads:: { ThreadDAO , ThreadMessageDAO } ;
26
30
use tokio:: sync:: Mutex ;
27
31
use user_completions:: UserCompletionDailyStatsDAO ;
@@ -115,17 +119,13 @@ fn make_pagination_query_with_condition(
115
119
impl DbConn {
116
120
#[ cfg( any( test, feature = "testutils" ) ) ]
117
121
pub async fn new_in_memory ( ) -> Result < Self > {
118
- use std:: { str:: FromStr , time :: Duration } ;
122
+ use std:: str:: FromStr ;
119
123
120
124
use sqlx:: sqlite:: SqlitePoolOptions ;
121
125
122
126
let options = SqliteConnectOptions :: from_str ( "sqlite::memory:" ) ?;
123
- let pool: Pool < Sqlite > = SqlitePoolOptions :: new ( )
124
- . max_connections ( 20 )
125
- . min_connections ( 2 )
126
- . acquire_timeout ( Duration :: from_secs ( 6 ) )
127
- . idle_timeout ( Duration :: from_secs ( 300 ) )
128
- . max_lifetime ( Duration :: from_secs ( 3600 ) )
127
+ let pool = SqlitePoolOptions :: new ( )
128
+ . max_connections ( 1 )
129
129
. connect_with ( options)
130
130
. await ?;
131
131
DbConn :: init_db ( pool) . await
@@ -173,7 +173,14 @@ impl DbConn {
173
173
. journal_mode ( sqlx:: sqlite:: SqliteJournalMode :: Wal )
174
174
. filename ( db_file)
175
175
. create_if_missing ( true ) ;
176
- let pool = SqlitePool :: connect_with ( options) . await ?;
176
+ let pool = SqlitePoolOptions :: new ( )
177
+ . max_connections ( 64 )
178
+ . min_connections ( 2 )
179
+ . acquire_timeout ( Duration :: from_secs ( 6 ) )
180
+ . idle_timeout ( Duration :: from_secs ( 300 ) )
181
+ . max_lifetime ( Duration :: from_secs ( 3600 ) )
182
+ . connect_with ( options)
183
+ . await ?;
177
184
Self :: backup_db ( db_file, & pool) . await ?;
178
185
Self :: init_db ( pool) . await
179
186
}
0 commit comments