@@ -15,7 +15,7 @@ use super::{
15
15
connection:: { Connection , RustConnection } ,
16
16
} ;
17
17
18
- /// `PSQLPool` for internal use only.
18
+ /// `PSQLPool` is for internal use only.
19
19
///
20
20
/// It is not exposed to python.
21
21
pub struct RustPSQLPool {
@@ -27,7 +27,7 @@ pub struct RustPSQLPool {
27
27
db_name : Option < String > ,
28
28
max_db_pool_size : Option < usize > ,
29
29
conn_recycling_method : Option < ConnRecyclingMethod > ,
30
- db_pool : Arc < tokio :: sync :: RwLock < Option < Pool > > > ,
30
+ db_pool : Option < Pool > ,
31
31
}
32
32
33
33
impl RustPSQLPool {
@@ -53,7 +53,7 @@ impl RustPSQLPool {
53
53
db_name,
54
54
max_db_pool_size,
55
55
conn_recycling_method,
56
- db_pool : Arc :: new ( tokio :: sync :: RwLock :: new ( None ) ) ,
56
+ db_pool : None ,
57
57
}
58
58
}
59
59
}
@@ -64,11 +64,8 @@ impl RustPSQLPool {
64
64
/// # Errors
65
65
/// May return Err Result if cannot get new connection from the pool.
66
66
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
72
69
. as_ref ( )
73
70
. ok_or ( RustPSQLDriverError :: DatabasePoolError (
74
71
"Database pool is not initialized" . into ( ) ,
@@ -92,11 +89,8 @@ impl RustPSQLPool {
92
89
querystring : String ,
93
90
parameters : Vec < PythonDTO > ,
94
91
) -> 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
100
94
. as_ref ( )
101
95
. ok_or ( RustPSQLDriverError :: DatabasePoolError (
102
96
"Database pool is not initialized" . into ( ) ,
@@ -123,8 +117,7 @@ impl RustPSQLPool {
123
117
/// # Errors
124
118
/// May return Err Result if Database pool is already initialized,
125
119
/// `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 < ( ) > {
128
121
let dsn = self . dsn . clone ( ) ;
129
122
let password = self . password . clone ( ) ;
130
123
let username = self . username . clone ( ) ;
@@ -134,8 +127,7 @@ impl RustPSQLPool {
134
127
let conn_recycling_method = self . conn_recycling_method ;
135
128
let max_db_pool_size = self . max_db_pool_size ;
136
129
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 ( ) {
139
131
return Err ( RustPSQLDriverError :: DatabasePoolError (
140
132
"Database pool is already initialized" . into ( ) ,
141
133
) ) ;
@@ -188,7 +180,7 @@ impl RustPSQLPool {
188
180
db_pool_builder = db_pool_builder. max_size ( max_db_pool_size) ;
189
181
}
190
182
191
- * db_pool_guard = Some ( db_pool_builder. build ( ) ?) ;
183
+ self . db_pool = Some ( db_pool_builder. build ( ) ?) ;
192
184
Ok ( ( ) )
193
185
}
194
186
}
@@ -223,7 +215,7 @@ impl PSQLPool {
223
215
db_name,
224
216
max_db_pool_size,
225
217
conn_recycling_method,
226
- db_pool : Arc :: new ( tokio :: sync :: RwLock :: new ( None ) ) ,
218
+ db_pool : None ,
227
219
} ) ) ,
228
220
}
229
221
}
@@ -235,8 +227,8 @@ impl PSQLPool {
235
227
pub fn startup < ' a > ( & ' a self , py : Python < ' a > ) -> RustPSQLDriverPyResult < & ' a PyAny > {
236
228
let psql_pool_arc = self . rust_psql_pool . clone ( ) ;
237
229
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 ( ) ?;
240
232
Ok ( ( ) )
241
233
} )
242
234
}
0 commit comments