@@ -12,7 +12,7 @@ use crate::{
12
12
13
13
use super :: { common_options:: ConnRecyclingMethod , connection:: Connection } ;
14
14
15
- /// `PSQLPool` for internal use only.
15
+ /// `PSQLPool` is for internal use only.
16
16
///
17
17
/// It is not exposed to python.
18
18
pub struct RustPSQLPool {
@@ -24,7 +24,7 @@ pub struct RustPSQLPool {
24
24
db_name : Option < String > ,
25
25
max_db_pool_size : Option < usize > ,
26
26
conn_recycling_method : Option < ConnRecyclingMethod > ,
27
- db_pool : Arc < tokio :: sync :: RwLock < Option < Pool > > > ,
27
+ db_pool : Option < Pool > ,
28
28
}
29
29
30
30
impl RustPSQLPool {
@@ -50,7 +50,7 @@ impl RustPSQLPool {
50
50
db_name,
51
51
max_db_pool_size,
52
52
conn_recycling_method,
53
- db_pool : Arc :: new ( tokio :: sync :: RwLock :: new ( None ) ) ,
53
+ db_pool : None ,
54
54
}
55
55
}
56
56
}
@@ -61,11 +61,8 @@ impl RustPSQLPool {
61
61
/// # Errors
62
62
/// May return Err Result if cannot get new connection from the pool.
63
63
pub async fn inner_connection ( & self ) -> RustPSQLDriverPyResult < Connection > {
64
- let db_pool_arc = self . db_pool . clone ( ) ;
65
-
66
- let db_pool_guard = db_pool_arc. read ( ) . await ;
67
-
68
- let db_pool_manager = db_pool_guard
64
+ let db_pool_manager = self
65
+ . db_pool
69
66
. as_ref ( )
70
67
. ok_or ( RustPSQLDriverError :: DatabasePoolError (
71
68
"Database pool is not initialized" . into ( ) ,
@@ -89,11 +86,8 @@ impl RustPSQLPool {
89
86
querystring : String ,
90
87
parameters : Vec < PythonDTO > ,
91
88
) -> RustPSQLDriverPyResult < PSQLDriverPyQueryResult > {
92
- let db_pool_arc = self . db_pool . clone ( ) ;
93
-
94
- let db_pool_guard = db_pool_arc. read ( ) . await ;
95
-
96
- let db_pool_manager = db_pool_guard
89
+ let db_pool_manager = self
90
+ . db_pool
97
91
. as_ref ( )
98
92
. ok_or ( RustPSQLDriverError :: DatabasePoolError (
99
93
"Database pool is not initialized" . into ( ) ,
@@ -120,8 +114,7 @@ impl RustPSQLPool {
120
114
/// # Errors
121
115
/// May return Err Result if Database pool is already initialized,
122
116
/// `max_db_pool_size` is less than 2 or it's impossible to build db pool.
123
- pub async fn inner_startup ( & self ) -> RustPSQLDriverPyResult < ( ) > {
124
- let db_pool_arc = self . db_pool . clone ( ) ;
117
+ pub fn inner_startup ( & mut self ) -> RustPSQLDriverPyResult < ( ) > {
125
118
let dsn = self . dsn . clone ( ) ;
126
119
let password = self . password . clone ( ) ;
127
120
let username = self . username . clone ( ) ;
@@ -131,8 +124,7 @@ impl RustPSQLPool {
131
124
let conn_recycling_method = self . conn_recycling_method ;
132
125
let max_db_pool_size = self . max_db_pool_size ;
133
126
134
- let mut db_pool_guard = db_pool_arc. write ( ) . await ;
135
- if db_pool_guard. is_some ( ) {
127
+ if self . db_pool . is_some ( ) {
136
128
return Err ( RustPSQLDriverError :: DatabasePoolError (
137
129
"Database pool is already initialized" . into ( ) ,
138
130
) ) ;
@@ -185,7 +177,7 @@ impl RustPSQLPool {
185
177
db_pool_builder = db_pool_builder. max_size ( max_db_pool_size) ;
186
178
}
187
179
188
- * db_pool_guard = Some ( db_pool_builder. build ( ) ?) ;
180
+ self . db_pool = Some ( db_pool_builder. build ( ) ?) ;
189
181
Ok ( ( ) )
190
182
}
191
183
}
@@ -220,7 +212,7 @@ impl PSQLPool {
220
212
db_name,
221
213
max_db_pool_size,
222
214
conn_recycling_method,
223
- db_pool : Arc :: new ( tokio :: sync :: RwLock :: new ( None ) ) ,
215
+ db_pool : None ,
224
216
} ) ) ,
225
217
}
226
218
}
@@ -232,8 +224,8 @@ impl PSQLPool {
232
224
pub fn startup < ' a > ( & ' a self , py : Python < ' a > ) -> RustPSQLDriverPyResult < & ' a PyAny > {
233
225
let psql_pool_arc = self . rust_psql_pool . clone ( ) ;
234
226
rustengine_future ( py, async move {
235
- let db_pool_guard = psql_pool_arc. write ( ) . await ;
236
- db_pool_guard. inner_startup ( ) . await ?;
227
+ let mut db_pool_guard = psql_pool_arc. write ( ) . await ;
228
+ db_pool_guard. inner_startup ( ) ?;
237
229
Ok ( ( ) )
238
230
} )
239
231
}
0 commit comments