improve postgresql performance
This commit is contained in:
+33
-5
@@ -106,6 +106,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Create a reference to db_pool for use throughout the code
|
||||
let db_pool_ref = db_pool.as_ref();
|
||||
|
||||
// Initialize path service
|
||||
let path_service = Arc::new(PathService::new(storage_path.clone()));
|
||||
@@ -531,10 +534,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing::info!("Compression service initialized with buffer pool support");
|
||||
|
||||
// Initialize auth services if enabled and database connection is available
|
||||
let auth_services = if config.features.enable_auth && db_pool.is_some() {
|
||||
let auth_services = if config.features.enable_auth && db_pool_ref.is_some() {
|
||||
match create_auth_services(
|
||||
&config,
|
||||
db_pool.as_ref().unwrap().clone(),
|
||||
db_pool_ref.unwrap().clone(),
|
||||
Some(folder_service.clone()) // Pasar el servicio de carpetas para creación automática de carpetas de usuario
|
||||
).await {
|
||||
Ok(services) => {
|
||||
@@ -628,7 +631,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Initialize favorites service if database is available
|
||||
let favorites_service: Option<Arc<dyn application::ports::favorites_ports::FavoritesUseCase>> =
|
||||
if let Some(ref pool) = db_pool {
|
||||
if let Some(pool) = db_pool_ref {
|
||||
// Create a new favorites service with the database pool
|
||||
let favorites_service = Arc::new(FavoritesService::new(
|
||||
pool.clone()
|
||||
@@ -643,7 +646,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Initialize recent items service if database is available
|
||||
let recent_service: Option<Arc<dyn application::ports::recent_ports::RecentItemsUseCase>> =
|
||||
if let Some(ref pool) = db_pool {
|
||||
if let Some(pool) = db_pool_ref {
|
||||
// Create a new service with the database pool
|
||||
let service = Arc::new(application::services::recent_service::RecentService::new(
|
||||
pool.clone(),
|
||||
@@ -680,7 +683,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
|
||||
// Add database pool if available
|
||||
if let Some(pool) = db_pool {
|
||||
if let Some(pool) = db_pool.clone() {
|
||||
app_state = app_state.with_database(pool);
|
||||
}
|
||||
|
||||
@@ -700,6 +703,31 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
app_state = app_state.with_recent_service(service);
|
||||
}
|
||||
|
||||
// Initialize storage usage service
|
||||
let _storage_usage_service = if let Some(pool) = db_pool_ref {
|
||||
// Create a user repository that implements UserStoragePort
|
||||
let user_repository = Arc::new(
|
||||
infrastructure::repositories::pg::UserPgRepository::new(pool.clone())
|
||||
);
|
||||
|
||||
// Create storage usage service that uses database for user information
|
||||
// and file repository for storage calculation
|
||||
let service = Arc::new(application::services::storage_usage_service::StorageUsageService::new(
|
||||
file_repository.clone(),
|
||||
user_repository,
|
||||
));
|
||||
|
||||
tracing::info!("Storage usage service initialized successfully");
|
||||
|
||||
// Add the service to the app state
|
||||
app_state = app_state.with_storage_usage_service(service.clone());
|
||||
|
||||
Some(service)
|
||||
} else {
|
||||
tracing::info!("Storage usage service is disabled (requires database connection)");
|
||||
None
|
||||
};
|
||||
|
||||
// Wrap in Arc after all modifications
|
||||
let app_state = Arc::new(app_state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user