@@ -15,7 +15,7 @@ use super::{
1515 connection:: { Connection , RustConnection } ,
1616} ;
1717
18- /// `PSQLPool` for internal use only.
18+ /// `PSQLPool` is for internal use only.
1919///
2020/// It is not exposed to python.
2121pub struct RustPSQLPool {
@@ -27,7 +27,7 @@ pub struct RustPSQLPool {
2727 db_name : Option < String > ,
2828 max_db_pool_size : Option < usize > ,
2929 conn_recycling_method : Option < ConnRecyclingMethod > ,
30- db_pool : Arc < tokio :: sync :: RwLock < Option < Pool > > > ,
30+ db_pool : Option < Pool > ,
3131}
3232
3333impl RustPSQLPool {
@@ -53,7 +53,7 @@ impl RustPSQLPool {
5353 db_name,
5454 max_db_pool_size,
5555 conn_recycling_method,
56- db_pool : Arc :: new ( tokio :: sync :: RwLock :: new ( None ) ) ,
56+ db_pool : None ,
5757 }
5858 }
5959}
@@ -64,11 +64,8 @@ impl RustPSQLPool {
6464 /// # Errors
6565 /// May return Err Result if cannot get new connection from the pool.
6666 pub async fn inner_connection ( & self ) -> RustPSQLDriverPyResult < Connection > {
67- let db_pool_arc = self . db_pool . clone ( ) ;
68-
69- let db_pool_guard = db_pool_arc. read ( ) . await ;
70-
71- let db_pool_manager = db_pool_guard
67+ let db_pool_manager = self
68+ . db_pool
7269 . as_ref ( )
7370 . ok_or ( RustPSQLDriverError :: DatabasePoolError (
7471 "Database pool is not initialized" . into ( ) ,
@@ -92,11 +89,8 @@ impl RustPSQLPool {
9289 querystring : String ,
9390 parameters : Vec < PythonDTO > ,
9491 ) -> RustPSQLDriverPyResult < PSQLDriverPyQueryResult > {
95- let db_pool_arc = self . db_pool . clone ( ) ;
96-
97- let db_pool_guard = db_pool_arc. read ( ) . await ;
98-
99- let db_pool_manager = db_pool_guard
92+ let db_pool_manager = self
93+ . db_pool
10094 . as_ref ( )
10195 . ok_or ( RustPSQLDriverError :: DatabasePoolError (
10296 "Database pool is not initialized" . into ( ) ,
@@ -123,8 +117,7 @@ impl RustPSQLPool {
123117 /// # Errors
124118 /// May return Err Result if Database pool is already initialized,
125119 /// `max_db_pool_size` is less than 2 or it's impossible to build db pool.
126- pub async fn inner_startup ( & self ) -> RustPSQLDriverPyResult < ( ) > {
127- let db_pool_arc = self . db_pool . clone ( ) ;
120+ pub fn inner_startup ( & mut self ) -> RustPSQLDriverPyResult < ( ) > {
128121 let dsn = self . dsn . clone ( ) ;
129122 let password = self . password . clone ( ) ;
130123 let username = self . username . clone ( ) ;
@@ -134,8 +127,7 @@ impl RustPSQLPool {
134127 let conn_recycling_method = self . conn_recycling_method ;
135128 let max_db_pool_size = self . max_db_pool_size ;
136129
137- let mut db_pool_guard = db_pool_arc. write ( ) . await ;
138- if db_pool_guard. is_some ( ) {
130+ if self . db_pool . is_some ( ) {
139131 return Err ( RustPSQLDriverError :: DatabasePoolError (
140132 "Database pool is already initialized" . into ( ) ,
141133 ) ) ;
@@ -188,7 +180,7 @@ impl RustPSQLPool {
188180 db_pool_builder = db_pool_builder. max_size ( max_db_pool_size) ;
189181 }
190182
191- * db_pool_guard = Some ( db_pool_builder. build ( ) ?) ;
183+ self . db_pool = Some ( db_pool_builder. build ( ) ?) ;
192184 Ok ( ( ) )
193185 }
194186}
@@ -223,7 +215,7 @@ impl PSQLPool {
223215 db_name,
224216 max_db_pool_size,
225217 conn_recycling_method,
226- db_pool : Arc :: new ( tokio :: sync :: RwLock :: new ( None ) ) ,
218+ db_pool : None ,
227219 } ) ) ,
228220 }
229221 }
@@ -235,8 +227,8 @@ impl PSQLPool {
235227 pub fn startup < ' a > ( & ' a self , py : Python < ' a > ) -> RustPSQLDriverPyResult < & ' a PyAny > {
236228 let psql_pool_arc = self . rust_psql_pool . clone ( ) ;
237229 rustengine_future ( py, async move {
238- let db_pool_guard = psql_pool_arc. write ( ) . await ;
239- db_pool_guard. inner_startup ( ) . await ?;
230+ let mut db_pool_guard = psql_pool_arc. write ( ) . await ;
231+ db_pool_guard. inner_startup ( ) ?;
240232 Ok ( ( ) )
241233 } )
242234 }
0 commit comments