Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 1bdc8ec

Browse files
pimeysJakub Wieczorek
authored andcommitted
fix(pool): Skip all type info queries, we run in text mode
1 parent 0f0a27d commit 1bdc8ec

File tree

8 files changed

+11
-297
lines changed

8 files changed

+11
-297
lines changed

postgres/src/config.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,6 @@ impl Config {
433433
self
434434
}
435435

436-
/// When enabled, the client skips all internal caching for statements,
437-
/// allowing usage with a connection pool with transaction mode.
438-
///
439-
/// Defaults to `false`.
440-
pub fn transaction_pool_mode(&mut self, enable: bool) -> &mut Config {
441-
self.config.transaction_pool_mode(enable);
442-
self
443-
}
444-
445-
/// Gets the transaction pool mode status.
446-
pub fn get_transaction_pool_mode(&self) -> bool {
447-
self.config.get_transaction_pool_mode()
448-
}
449-
450436
/// Opens a connection to a PostgreSQL database.
451437
pub fn connect<T>(&self, tls: T) -> Result<Client, Error>
452438
where

tokio-postgres/src/client.rs

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,9 @@ impl Responses {
6161
}
6262
}
6363

64-
/// A cache of type info and prepared statements for fetching type info
65-
/// (corresponding to the queries in the [prepare](prepare) module).
66-
#[derive(Default)]
67-
struct CachedTypeInfo {
68-
/// A statement for basic information for a type from its
69-
/// OID. Corresponds to [TYPEINFO_QUERY](prepare::TYPEINFO_QUERY) (or its
70-
/// fallback).
71-
typeinfo: Option<Statement>,
72-
/// A statement for getting information for a composite type from its OID.
73-
/// Corresponds to [TYPEINFO_QUERY](prepare::TYPEINFO_COMPOSITE_QUERY).
74-
typeinfo_composite: Option<Statement>,
75-
/// A statement for getting information for a composite type from its OID.
76-
/// Corresponds to [TYPEINFO_QUERY](prepare::TYPEINFO_COMPOSITE_QUERY) (or
77-
/// its fallback).
78-
typeinfo_enum: Option<Statement>,
79-
80-
/// Cache of types already looked up.
81-
types: HashMap<Oid, Type>,
82-
}
83-
8464
pub struct InnerClient {
8565
sender: mpsc::UnboundedSender<Request>,
86-
transaction_pool_mode: bool,
87-
cached_typeinfo: Mutex<CachedTypeInfo>,
66+
cached_typeinfo: Mutex<HashMap<Oid, Type>>,
8867

8968
/// A buffer to use when writing out postgres commands.
9069
buffer: Mutex<BytesMut>,
@@ -104,66 +83,12 @@ impl InnerClient {
10483
})
10584
}
10685

107-
pub fn typeinfo(&self) -> Option<Statement> {
108-
if self.transaction_pool_mode {
109-
None
110-
} else {
111-
self.cached_typeinfo.lock().typeinfo.clone()
112-
}
113-
}
114-
115-
pub fn set_typeinfo(&self, statement: &Statement) {
116-
if !self.transaction_pool_mode {
117-
self.cached_typeinfo.lock().typeinfo = Some(statement.clone());
118-
}
119-
}
120-
121-
pub fn typeinfo_composite(&self) -> Option<Statement> {
122-
if self.transaction_pool_mode {
123-
None
124-
} else {
125-
self.cached_typeinfo.lock().typeinfo_composite.clone()
126-
}
127-
}
128-
129-
pub fn set_typeinfo_composite(&self, statement: &Statement) {
130-
if !self.transaction_pool_mode {
131-
self.cached_typeinfo.lock().typeinfo_composite = Some(statement.clone());
132-
}
133-
}
134-
135-
pub fn typeinfo_enum(&self) -> Option<Statement> {
136-
if self.transaction_pool_mode {
137-
None
138-
} else {
139-
self.cached_typeinfo.lock().typeinfo_enum.clone()
140-
}
141-
}
142-
143-
pub fn set_typeinfo_enum(&self, statement: &Statement) {
144-
if !self.transaction_pool_mode {
145-
self.cached_typeinfo.lock().typeinfo_enum = Some(statement.clone());
146-
}
147-
}
148-
14986
pub fn type_(&self, oid: Oid) -> Option<Type> {
150-
if self.transaction_pool_mode {
151-
None
152-
} else {
153-
self.cached_typeinfo.lock().types.get(&oid).cloned()
154-
}
155-
}
156-
157-
pub fn set_type(&self, oid: Oid, type_: &Type) {
158-
if !self.transaction_pool_mode {
159-
self.cached_typeinfo.lock().types.insert(oid, type_.clone());
160-
}
87+
self.cached_typeinfo.lock().get(&oid).cloned()
16188
}
16289

16390
pub fn clear_type_cache(&self) {
164-
if !self.transaction_pool_mode {
165-
self.cached_typeinfo.lock().types.clear();
166-
}
91+
self.cached_typeinfo.lock().clear();
16792
}
16893

16994
/// Call the given function with a buffer to be used when writing out
@@ -217,14 +142,12 @@ impl Client {
217142
ssl_mode: SslMode,
218143
process_id: i32,
219144
secret_key: i32,
220-
transaction_pool_mode: bool,
221145
) -> Client {
222146
Client {
223147
inner: Arc::new(InnerClient {
224148
sender,
225149
cached_typeinfo: Default::default(),
226150
buffer: Default::default(),
227-
transaction_pool_mode,
228151
}),
229152
#[cfg(feature = "runtime")]
230153
socket_config: None,

tokio-postgres/src/config.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ pub struct Config {
210210
pub(crate) channel_binding: ChannelBinding,
211211
pub(crate) load_balance_hosts: LoadBalanceHosts,
212212
pub(crate) max_backend_message_size: Option<usize>,
213-
pub(crate) transaction_pool_mode: bool,
214213
}
215214

216215
impl Default for Config {
@@ -245,7 +244,6 @@ impl Config {
245244
channel_binding: ChannelBinding::Prefer,
246245
load_balance_hosts: LoadBalanceHosts::Disable,
247246
max_backend_message_size: None,
248-
transaction_pool_mode: false,
249247
}
250248
}
251249

@@ -513,20 +511,6 @@ impl Config {
513511
self.channel_binding
514512
}
515513

516-
/// When enabled, the client skips all internal caching for statements,
517-
/// allowing usage with a connection pool with transaction mode.
518-
///
519-
/// Defaults to `false`.
520-
pub fn transaction_pool_mode(&mut self, enable: bool) -> &mut Config {
521-
self.transaction_pool_mode = enable;
522-
self
523-
}
524-
525-
/// Gets the transaction pool mode status.
526-
pub fn get_transaction_pool_mode(&self) -> bool {
527-
self.transaction_pool_mode
528-
}
529-
530514
/// Sets the host load balancing behavior.
531515
///
532516
/// Defaults to `disable`.

tokio-postgres/src/connect_raw.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,7 @@ where
113113

114114
let (sender, receiver) = mpsc::unbounded();
115115

116-
let client = Client::new(
117-
sender,
118-
config.ssl_mode,
119-
process_id,
120-
secret_key,
121-
config.transaction_pool_mode,
122-
);
123-
116+
let client = Client::new(sender, config.ssl_mode, process_id, secret_key);
124117
let connection = Connection::new(stream.inner, stream.delayed, parameters, receiver);
125118

126119
Ok((client, connection))

0 commit comments

Comments
 (0)