Refactor database error handling across repositories to use IntoDbResult for improved error management
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m30s
test / unit (pull_request) Successful in 16m10s
test / integration (pull_request) Failing after 16m44s
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m30s
test / unit (pull_request) Successful in 16m10s
test / integration (pull_request) Failing after 16m44s
- Updated PgNotificationRepository to utilize IntoDbResult for error handling in various methods. - Refactored PgRemoteActorRepository to replace manual error mapping with IntoDbResult. - Modified PgRemoteActorConnectionRepository to implement IntoDbResult for error handling. - Adjusted PgTagRepository to use IntoDbResult for consistent error management. - Introduced test_helpers module for seeding users and thoughts in tests. - Enhanced PgThoughtRepository to leverage IntoDbResult for error handling. - Updated PgTopFriendRepository to utilize IntoDbResult for error management. - Refactored PgUserRepository to implement IntoDbResult for error handling. - Added constants for pagination defaults in requests. - Introduced MAX_TOP_FRIENDS constant for top friends validation. - Refactored JWT expiration time to use a constant. - Improved rate limiter configuration with constants for better readability. - Added utility methods for FollowState and Visibility enums for string conversions. - Introduced maximum length constants for Username, Email, and Content value objects. - Cleaned up test modules by removing redundant code and utilizing a shared testing state.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const JWT_TTL_SECS: i64 = 86_400 * 30;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
@@ -107,7 +109,7 @@ pub async fn build(cfg: &Config) -> Infrastructure {
|
||||
search: Arc::new(postgres_search::PgSearchRepository::new(pool.clone())),
|
||||
auth: Arc::new(auth::JwtAuthService::new(
|
||||
cfg.jwt_secret.clone(),
|
||||
86400 * 30,
|
||||
JWT_TTL_SECS,
|
||||
)),
|
||||
hasher: Arc::new(auth::Argon2PasswordHasher),
|
||||
events: event_publisher,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
mod config;
|
||||
mod factory;
|
||||
|
||||
const MS_PER_MINUTE: u64 = 60_000;
|
||||
const RATE_LIMITER_CLEANUP_INTERVAL_SECS: u64 = 60;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use tower_http::cors::{AllowOrigin, CorsLayer};
|
||||
@@ -46,7 +49,7 @@ async fn main() {
|
||||
|
||||
// per_millisecond sets the token replenishment interval.
|
||||
// rate_limit = max requests/minute => replenish every (60000 / rate_limit) ms.
|
||||
let ms = (60_000u64).saturating_div(rate_limit as u64).max(1);
|
||||
let ms = MS_PER_MINUTE.saturating_div(rate_limit as u64).max(1);
|
||||
let governor_conf = Arc::new(
|
||||
GovernorConfigBuilder::default()
|
||||
.per_millisecond(ms)
|
||||
@@ -58,7 +61,9 @@ async fn main() {
|
||||
|
||||
let limiter = governor_conf.limiter().clone();
|
||||
tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(60));
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(
|
||||
RATE_LIMITER_CLEANUP_INTERVAL_SECS,
|
||||
));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
limiter.retain_recent();
|
||||
|
||||
Reference in New Issue
Block a user