|
1 | 1 | //! Application-wide components in a struct accessible from each request
|
2 | 2 |
|
3 | 3 | use crate::config;
|
4 |
| -use crate::db::{connection_url, ConnectionConfig, DieselPool, DieselPooledConn, PoolError}; |
| 4 | +use crate::db::{connection_url, ConnectionConfig, DieselPool}; |
5 | 5 | use std::ops::Deref;
|
6 | 6 | use std::sync::atomic::AtomicUsize;
|
7 | 7 | use std::sync::Arc;
|
@@ -208,48 +208,12 @@ impl App {
|
208 | 208 | &self.config.session_key
|
209 | 209 | }
|
210 | 210 |
|
211 |
| - /// Obtain a read/write database connection from the primary pool |
212 |
| - #[instrument(skip_all)] |
213 |
| - pub fn db_write(&self) -> Result<DieselPooledConn, PoolError> { |
214 |
| - self.primary_database.get() |
215 |
| - } |
216 |
| - |
217 | 211 | /// Obtain a read/write database connection from the async primary pool
|
218 | 212 | #[instrument(skip_all)]
|
219 | 213 | pub async fn db_write_async(&self) -> DeadpoolResult {
|
220 | 214 | self.deadpool_primary.get().await
|
221 | 215 | }
|
222 | 216 |
|
223 |
| - /// Obtain a readonly database connection from the replica pool |
224 |
| - /// |
225 |
| - /// If the replica pool is disabled or unavailable, the primary pool is used instead. |
226 |
| - #[instrument(skip_all)] |
227 |
| - pub fn db_read(&self) -> Result<DieselPooledConn, PoolError> { |
228 |
| - let Some(read_only_pool) = self.read_only_replica_database.as_ref() else { |
229 |
| - // Replica is disabled, but primary might be available |
230 |
| - return self.primary_database.get(); |
231 |
| - }; |
232 |
| - |
233 |
| - match read_only_pool.get() { |
234 |
| - // Replica is available |
235 |
| - Ok(connection) => Ok(connection), |
236 |
| - |
237 |
| - // Replica is not available, but primary might be available |
238 |
| - Err(PoolError::UnhealthyPool) => { |
239 |
| - let _ = self |
240 |
| - .instance_metrics |
241 |
| - .database_fallback_used |
242 |
| - .get_metric_with_label_values(&["follower"]) |
243 |
| - .map(|metric| metric.inc()); |
244 |
| - |
245 |
| - self.primary_database.get() |
246 |
| - } |
247 |
| - |
248 |
| - // Replica failed |
249 |
| - Err(error) => Err(error), |
250 |
| - } |
251 |
| - } |
252 |
| - |
253 | 217 | /// Obtain a readonly database connection from the replica pool
|
254 | 218 | ///
|
255 | 219 | /// If the replica pool is disabled or unavailable, the primary pool is used instead.
|
@@ -281,35 +245,6 @@ impl App {
|
281 | 245 | }
|
282 | 246 | }
|
283 | 247 |
|
284 |
| - /// Obtain a readonly database connection from the primary pool |
285 |
| - /// |
286 |
| - /// If the primary pool is unavailable, the replica pool is used instead, if not disabled. |
287 |
| - #[instrument(skip_all)] |
288 |
| - pub fn db_read_prefer_primary(&self) -> Result<DieselPooledConn, PoolError> { |
289 |
| - let Some(read_only_pool) = self.read_only_replica_database.as_ref() else { |
290 |
| - return self.primary_database.get(); |
291 |
| - }; |
292 |
| - |
293 |
| - match self.primary_database.get() { |
294 |
| - // Primary is available |
295 |
| - Ok(connection) => Ok(connection), |
296 |
| - |
297 |
| - // Primary is not available, but replica might be available |
298 |
| - Err(PoolError::UnhealthyPool) => { |
299 |
| - let _ = self |
300 |
| - .instance_metrics |
301 |
| - .database_fallback_used |
302 |
| - .get_metric_with_label_values(&["primary"]) |
303 |
| - .map(|metric| metric.inc()); |
304 |
| - |
305 |
| - read_only_pool.get() |
306 |
| - } |
307 |
| - |
308 |
| - // Primary failed |
309 |
| - Err(error) => Err(error), |
310 |
| - } |
311 |
| - } |
312 |
| - |
313 | 248 | /// Obtain a readonly database connection from the primary pool
|
314 | 249 | ///
|
315 | 250 | /// If the primary pool is unavailable, the replica pool is used instead, if not disabled.
|
|
0 commit comments