perf: replace dyn trait objects with concrete types to eliminate vtable overhead
Remove async-trait dependency and use native Rust async fn in traits. Replace Arc<dyn Trait> with Arc<ConcreteType> throughout the codebase to enable monomorphization and eliminate dynamic dispatch overhead. Key changes: - Remove write-behind cache (no implementation existed) - Fix should_transcode static method call - Use ContactStorageAdapter directly instead of dyn AddressBookUseCase - Clean up unused trait imports across services and DI https://claude.ai/code/session_01EbAFEfyJNLRmJHmmYDX3Tt
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
//! the `CalendarRepository` and `CalendarEventRepository` domain repositories.
|
||||
//! It bridges the gap between the application layer and the infrastructure layer.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -20,18 +19,20 @@ use crate::domain::entities::calendar::Calendar;
|
||||
use crate::domain::entities::calendar_event::CalendarEvent;
|
||||
use crate::domain::repositories::calendar_event_repository::CalendarEventRepository;
|
||||
use crate::domain::repositories::calendar_repository::CalendarRepository;
|
||||
use crate::infrastructure::repositories::pg::CalendarEventPgRepository;
|
||||
use crate::infrastructure::repositories::pg::CalendarPgRepository;
|
||||
|
||||
/// Adapter that implements CalendarStoragePort using domain repositories
|
||||
pub struct CalendarStorageAdapter {
|
||||
calendar_repository: Arc<dyn CalendarRepository>,
|
||||
event_repository: Arc<dyn CalendarEventRepository>,
|
||||
calendar_repository: Arc<CalendarPgRepository>,
|
||||
event_repository: Arc<CalendarEventPgRepository>,
|
||||
}
|
||||
|
||||
impl CalendarStorageAdapter {
|
||||
/// Creates a new CalendarStorageAdapter with the given repositories
|
||||
pub fn new(
|
||||
calendar_repository: Arc<dyn CalendarRepository>,
|
||||
event_repository: Arc<dyn CalendarEventRepository>,
|
||||
calendar_repository: Arc<CalendarPgRepository>,
|
||||
event_repository: Arc<CalendarEventPgRepository>,
|
||||
) -> Self {
|
||||
Self {
|
||||
calendar_repository,
|
||||
@@ -40,7 +41,6 @@ impl CalendarStorageAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CalendarStoragePort for CalendarStorageAdapter {
|
||||
// Calendar operations
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//! using the domain repositories. It bridges the gap between the application layer
|
||||
//! and the infrastructure layer for CardDAV functionality.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -22,20 +21,23 @@ use crate::common::errors::{DomainError, ErrorKind};
|
||||
use crate::domain::entities::contact::{Address, AddressBook, Contact, ContactGroup, Email, Phone};
|
||||
use crate::domain::repositories::address_book_repository::AddressBookRepository;
|
||||
use crate::domain::repositories::contact_repository::{ContactGroupRepository, ContactRepository};
|
||||
use crate::infrastructure::repositories::pg::AddressBookPgRepository;
|
||||
use crate::infrastructure::repositories::pg::ContactGroupPgRepository;
|
||||
use crate::infrastructure::repositories::pg::ContactPgRepository;
|
||||
|
||||
/// Adapter that implements AddressBookUseCase and ContactUseCase using domain repositories
|
||||
pub struct ContactStorageAdapter {
|
||||
address_book_repository: Arc<dyn AddressBookRepository>,
|
||||
contact_repository: Arc<dyn ContactRepository>,
|
||||
group_repository: Arc<dyn ContactGroupRepository>,
|
||||
address_book_repository: Arc<AddressBookPgRepository>,
|
||||
contact_repository: Arc<ContactPgRepository>,
|
||||
group_repository: Arc<ContactGroupPgRepository>,
|
||||
}
|
||||
|
||||
impl ContactStorageAdapter {
|
||||
/// Creates a new ContactStorageAdapter with the given repositories
|
||||
pub fn new(
|
||||
address_book_repository: Arc<dyn AddressBookRepository>,
|
||||
contact_repository: Arc<dyn ContactRepository>,
|
||||
group_repository: Arc<dyn ContactGroupRepository>,
|
||||
address_book_repository: Arc<AddressBookPgRepository>,
|
||||
contact_repository: Arc<ContactPgRepository>,
|
||||
group_repository: Arc<ContactGroupPgRepository>,
|
||||
) -> Self {
|
||||
Self {
|
||||
address_book_repository,
|
||||
@@ -217,7 +219,6 @@ impl ContactStorageAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AddressBookUseCase for ContactStorageAdapter {
|
||||
async fn create_address_book(
|
||||
&self,
|
||||
@@ -423,7 +424,6 @@ impl AddressBookUseCase for ContactStorageAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ContactUseCase for ContactStorageAdapter {
|
||||
async fn create_contact(&self, dto: CreateContactDto) -> Result<ContactDto, DomainError> {
|
||||
let address_book_id = Self::parse_uuid(&dto.address_book_id, "AddressBook")?;
|
||||
|
||||
@@ -2,7 +2,6 @@ use anyhow::Result;
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::application::ports::auth_ports::TokenServicePort;
|
||||
use crate::application::services::auth_application_service::AuthApplicationService;
|
||||
use crate::application::services::folder_service::FolderService;
|
||||
use crate::common::config::AppConfig;
|
||||
@@ -18,7 +17,7 @@ pub async fn create_auth_services(
|
||||
folder_service: Option<Arc<FolderService>>,
|
||||
) -> Result<AuthServices> {
|
||||
// Create JWT token service (TokenServicePort implementation)
|
||||
let token_service: Arc<dyn TokenServicePort> = Arc::new(JwtTokenService::new(
|
||||
let token_service: Arc<JwtTokenService> = Arc::new(JwtTokenService::new(
|
||||
config.auth.jwt_secret.clone(),
|
||||
config.auth.access_token_expiry_secs,
|
||||
config.auth.refresh_token_expiry_secs,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use sqlx::{PgPool, Row, types::Uuid};
|
||||
use std::sync::Arc;
|
||||
@@ -19,7 +18,6 @@ impl AddressBookPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AddressBookRepository for AddressBookPgRepository {
|
||||
async fn create_address_book(
|
||||
&self,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use crate::application::ports::auth_ports::AppPasswordStoragePort;
|
||||
use crate::common::errors::DomainError;
|
||||
use crate::domain::entities::app_password::AppPassword;
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
@@ -22,7 +21,6 @@ impl AppPasswordPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AppPasswordStoragePort for AppPasswordPgRepository {
|
||||
async fn create(&self, ap: AppPassword) -> Result<AppPassword, DomainError> {
|
||||
sqlx::query(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::{PgPool, Row, types::Uuid};
|
||||
use std::sync::Arc;
|
||||
@@ -19,7 +18,6 @@ impl CalendarEventPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CalendarEventRepository for CalendarEventPgRepository {
|
||||
async fn create_event(
|
||||
&self,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use sqlx::{PgPool, Row, types::Uuid};
|
||||
use std::sync::Arc;
|
||||
@@ -19,7 +18,6 @@ impl CalendarPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CalendarRepository for CalendarPgRepository {
|
||||
async fn create_calendar(&self, calendar: Calendar) -> CalendarRepositoryResult<Calendar> {
|
||||
let row = sqlx::query(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value as JsonValue;
|
||||
use sqlx::{PgPool, Row, types::Uuid};
|
||||
@@ -24,7 +23,6 @@ impl ContactGroupPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ContactGroupRepository for ContactGroupPgRepository {
|
||||
async fn create_group(&self, group: ContactGroup) -> ContactRepositoryResult<ContactGroup> {
|
||||
sqlx::query(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value as JsonValue;
|
||||
use sqlx::{PgPool, Row, types::Uuid};
|
||||
@@ -63,7 +62,6 @@ impl ContactPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ContactRepository for ContactPgRepository {
|
||||
async fn create_contact(&self, contact: Contact) -> ContactRepositoryResult<Contact> {
|
||||
// Convert domain entities to persistence DTOs for JSONB serialization
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! PostgreSQL repository for Device Authorization Grant (RFC 8628) codes.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sqlx::{PgPool, Row};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -49,7 +48,6 @@ impl DeviceCodePgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DeviceCodeStoragePort for DeviceCodePgRepository {
|
||||
async fn create_device_code(&self, dc: DeviceCode) -> Result<DeviceCode, DomainError> {
|
||||
sqlx::query(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use sqlx::{PgPool, Row};
|
||||
use std::sync::Arc;
|
||||
use tracing::error;
|
||||
@@ -19,7 +18,6 @@ impl FavoritesPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FavoritesRepositoryPort for FavoritesPgRepository {
|
||||
async fn get_favorites(&self, user_id: &str) -> Result<Vec<FavoriteItemDto>> {
|
||||
let user_uuid = Uuid::parse_str(user_id)?;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//! File paths are resolved by JOINing with `storage.folders.path` (the
|
||||
//! materialized path column), so no recursive CTEs or N+1 queries are needed.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use futures::{Stream, TryStreamExt};
|
||||
use moka::sync::Cache;
|
||||
@@ -17,16 +16,16 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::application::dtos::search_dto::SearchCriteriaDto;
|
||||
use crate::application::ports::dedup_ports::DedupPort;
|
||||
use crate::application::ports::storage_ports::FileReadPort;
|
||||
use crate::common::errors::DomainError;
|
||||
use crate::domain::entities::file::File;
|
||||
use crate::domain::services::path_service::StoragePath;
|
||||
use crate::infrastructure::services::dedup_service::DedupService;
|
||||
|
||||
/// File read repository backed by PostgreSQL metadata + blob storage.
|
||||
pub struct FileBlobReadRepository {
|
||||
pool: Arc<PgPool>,
|
||||
dedup: Arc<dyn DedupPort>,
|
||||
dedup: Arc<DedupService>,
|
||||
/// Lock-free cache: file_id → blob_hash.
|
||||
/// Populated by `get_file()` and `resolve_blob_hash()` (slow path).
|
||||
/// Entries persist until TTI expiry (30 s idle) or capacity eviction —
|
||||
@@ -37,7 +36,7 @@ pub struct FileBlobReadRepository {
|
||||
impl FileBlobReadRepository {
|
||||
pub fn new(
|
||||
pool: Arc<PgPool>,
|
||||
dedup: Arc<dyn DedupPort>,
|
||||
dedup: Arc<DedupService>,
|
||||
_folder_repo: Arc<super::folder_db_repository::FolderDbRepository>,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -115,7 +114,6 @@ impl FileBlobReadRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FileReadPort for FileBlobReadRepository {
|
||||
async fn get_file(&self, id: &str) -> Result<File, DomainError> {
|
||||
let row = sqlx::query_as::<
|
||||
@@ -890,14 +888,13 @@ impl FileReadPort for FileBlobReadRepository {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::common::stubs::StubDedupPort;
|
||||
use crate::infrastructure::repositories::pg::folder_db_repository::FolderDbRepository;
|
||||
|
||||
/// Helper: build a `FileBlobReadRepository` without a real PgPool.
|
||||
/// Only the moka `hash_cache` is exercised — no SQL is executed.
|
||||
fn make_repo() -> FileBlobReadRepository {
|
||||
let _folder_repo = Arc::new(FolderDbRepository::new_stub());
|
||||
// StubDedupPort satisfies the trait but is never called in cache-only tests
|
||||
let dedup: Arc<dyn DedupPort> = Arc::new(StubDedupPort);
|
||||
let dedup: Arc<DedupService> = Arc::new(StubDedupPort);
|
||||
// PgPool is required by the struct but we won't hit any SQL in these tests.
|
||||
// We create a repo with a stub pool placeholder — only hash_cache is tested.
|
||||
FileBlobReadRepository {
|
||||
|
||||
@@ -7,30 +7,29 @@
|
||||
//! File paths are resolved by querying the materialized `storage.folders.path`
|
||||
//! column (O(1) per lookup), so no recursive CTEs are needed.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sqlx::PgPool;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::application::ports::dedup_ports::DedupPort;
|
||||
use crate::application::ports::storage_ports::{CopyFolderTreeResult, FileWritePort};
|
||||
use crate::common::errors::DomainError;
|
||||
use crate::domain::entities::file::File;
|
||||
use crate::domain::services::path_service::StoragePath;
|
||||
|
||||
use super::folder_db_repository::FolderDbRepository;
|
||||
use crate::infrastructure::services::dedup_service::DedupService;
|
||||
|
||||
/// File write repository backed by PostgreSQL metadata + blob storage.
|
||||
pub struct FileBlobWriteRepository {
|
||||
pool: Arc<PgPool>,
|
||||
dedup: Arc<dyn DedupPort>,
|
||||
dedup: Arc<DedupService>,
|
||||
folder_repo: Arc<FolderDbRepository>,
|
||||
}
|
||||
|
||||
impl FileBlobWriteRepository {
|
||||
pub fn new(
|
||||
pool: Arc<PgPool>,
|
||||
dedup: Arc<dyn DedupPort>,
|
||||
dedup: Arc<DedupService>,
|
||||
folder_repo: Arc<FolderDbRepository>,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -180,7 +179,6 @@ impl FileBlobWriteRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FileWritePort for FileBlobWriteRepository {
|
||||
async fn save_file_from_temp(
|
||||
&self,
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
//! database triggers, so reading a folder's full path is always O(1) — no
|
||||
//! recursive CTEs or N+1 queries.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -72,7 +71,6 @@ impl FolderDbRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FolderRepository for FolderDbRepository {
|
||||
async fn create_folder(
|
||||
&self,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use sqlx::{PgPool, Row};
|
||||
use std::sync::Arc;
|
||||
use tracing::error;
|
||||
@@ -19,7 +18,6 @@ impl RecentItemsPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl RecentItemsRepositoryPort for RecentItemsPgRepository {
|
||||
async fn get_recent_items(&self, user_id: &str, limit: i32) -> Result<Vec<RecentItemDto>> {
|
||||
let user_uuid = Uuid::parse_str(user_id)?;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use futures::future::BoxFuture;
|
||||
use sqlx::{PgPool, Row};
|
||||
@@ -39,7 +38,6 @@ impl SessionPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SessionRepository for SessionPgRepository {
|
||||
/// Creates a new session using a transaction
|
||||
async fn create_session(&self, session: Session) -> SessionRepositoryResult<Session> {
|
||||
@@ -291,7 +289,6 @@ impl SessionRepository for SessionPgRepository {
|
||||
}
|
||||
|
||||
// Implementation of the storage port for the application layer
|
||||
#[async_trait]
|
||||
impl SessionStoragePort for SessionPgRepository {
|
||||
async fn create_session(&self, session: Session) -> Result<Session, DomainError> {
|
||||
SessionRepository::create_session(self, session)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -16,7 +15,6 @@ impl SettingsPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SettingsRepository for SettingsPgRepository {
|
||||
async fn get(&self, key: &str) -> Result<Option<String>, DomainError> {
|
||||
let row =
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use sqlx::{PgPool, Row};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -72,7 +71,6 @@ impl SharePgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ShareStoragePort for SharePgRepository {
|
||||
async fn save_share(&self, share: &Share) -> Result<Share, DomainError> {
|
||||
let row = sqlx::query(
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//! and `storage.folders`. There is no separate trash table — trashed items
|
||||
//! are files/folders with `is_trashed = TRUE`.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
@@ -65,7 +64,6 @@ impl TrashDbRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl TrashRepository for TrashDbRepository {
|
||||
async fn add_to_trash(&self, _item: &TrashedItem) -> Result<()> {
|
||||
// No-op: the actual flagging is done by FileWritePort::move_to_trash
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use futures::future::BoxFuture;
|
||||
use sqlx::{PgPool, Row};
|
||||
use std::sync::Arc;
|
||||
@@ -44,7 +43,6 @@ impl UserPgRepository {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl UserRepository for UserPgRepository {
|
||||
/// Creates a new user using a transaction
|
||||
async fn create_user(&self, user: User) -> UserRepositoryResult<User> {
|
||||
@@ -619,7 +617,6 @@ impl UserRepository for UserPgRepository {
|
||||
}
|
||||
|
||||
// Storage port implementation for the application layer
|
||||
#[async_trait]
|
||||
impl UserStoragePort for UserPgRepository {
|
||||
async fn create_user(&self, user: User) -> Result<User, DomainError> {
|
||||
UserRepository::create_user(self, user)
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
//! 3. HEAD /api/uploads/:id → Check progress
|
||||
//! 4. POST /api/uploads/:id/complete → Finalize and assemble
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use dashmap::DashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -755,7 +754,6 @@ impl ChunkedUploadService {
|
||||
|
||||
// ─── Port implementation ─────────────────────────────────────────────────────
|
||||
|
||||
#[async_trait]
|
||||
impl ChunkedUploadPort for ChunkedUploadService {
|
||||
async fn create_session(
|
||||
&self,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use flate2::Compression;
|
||||
use flate2::bufread::GzDecoder;
|
||||
@@ -43,7 +42,6 @@ impl From<CompressionLevel> for Compression {
|
||||
const COMPRESSION_SIZE_THRESHOLD: u64 = 1024 * 50; // 50KB
|
||||
|
||||
/// Interface for compression services
|
||||
#[async_trait]
|
||||
pub trait CompressionService: Send + Sync {
|
||||
/// Compresses data in memory
|
||||
async fn compress_data(&self, data: &[u8], level: CompressionLevel) -> io::Result<Vec<u8>>;
|
||||
@@ -88,7 +86,6 @@ impl GzipCompressionService {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CompressionService for GzipCompressionService {
|
||||
/// Compresses data in memory using Gzip
|
||||
async fn compress_data(&self, data: &[u8], level: CompressionLevel) -> io::Result<Vec<u8>> {
|
||||
@@ -258,7 +255,6 @@ impl From<PortCompressionLevel> for CompressionLevel {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CompressionPort for GzipCompressionService {
|
||||
async fn compress_data(
|
||||
&self,
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
//! - 30-50% storage reduction typical
|
||||
//! - Faster uploads for existing content (instant dedup)
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use futures::stream::{self, StreamExt};
|
||||
use futures::{Stream, TryStreamExt};
|
||||
@@ -802,7 +801,6 @@ impl DedupService {
|
||||
|
||||
// ─── Port implementation ─────────────────────────────────────────────────────
|
||||
|
||||
#[async_trait]
|
||||
impl DedupPort for DedupService {
|
||||
async fn store_bytes(
|
||||
&self,
|
||||
|
||||
@@ -198,9 +198,7 @@ pub type SharedFileContentCache = Arc<FileContentCache>;
|
||||
// ─── ContentCachePort implementation ─────────────────────────
|
||||
|
||||
use crate::application::ports::cache_ports::ContentCachePort;
|
||||
use async_trait::async_trait;
|
||||
|
||||
#[async_trait]
|
||||
impl ContentCachePort for FileContentCache {
|
||||
fn should_cache(&self, size: usize) -> bool {
|
||||
FileContentCache::should_cache(self, size)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@@ -63,7 +62,6 @@ impl FileSystemI18nService {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl I18nService for FileSystemI18nService {
|
||||
async fn translate(&self, key: &str, locale: Locale) -> I18nResult<String> {
|
||||
// Check if translations are cached
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
//! - Supports JPEG, PNG, GIF → WebP conversion
|
||||
//! - Falls back to original if conversion fails or result is larger
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use image::ImageFormat;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -392,7 +391,6 @@ impl From<PortOutputFormat> for OutputFormat {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ImageTranscodePort for ImageTranscodeService {
|
||||
fn can_transcode(&self, mime_type: &str) -> bool {
|
||||
ImageTranscodeService::can_transcode(mime_type)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
//! Supports both RSA (RS256, RS384, RS512) and EC (ES256, ES384) algorithms.
|
||||
//! Compatible with Authentik, Keycloak, and any standard OIDC provider.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::Deserialize;
|
||||
use std::sync::RwLock;
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -293,7 +292,6 @@ impl OidcService {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl OidcServicePort for OidcService {
|
||||
async fn get_authorize_url(
|
||||
&self,
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
use argon2::password_hash::SaltString;
|
||||
use argon2::{Algorithm, Argon2, Params, PasswordHash, PasswordHasher, PasswordVerifier, Version};
|
||||
use async_trait::async_trait;
|
||||
use rand_core::OsRng;
|
||||
|
||||
use crate::application::ports::auth_ports::PasswordHasherPort;
|
||||
@@ -57,7 +56,6 @@ impl Argon2PasswordHasher {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl PasswordHasherPort for Argon2PasswordHasher {
|
||||
async fn hash_password(&self, password: &str) -> Result<String, DomainError> {
|
||||
let pwd = password.to_owned();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
//!
|
||||
//! StoragePath (Value Object) remains in domain/services/path_service.rs
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tokio::fs;
|
||||
|
||||
@@ -116,7 +115,6 @@ impl PathService {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl StoragePort for PathService {
|
||||
fn resolve_path(&self, storage_path: &StoragePath) -> PathBuf {
|
||||
let mut path = self.root_path.clone();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use image::{ImageFormat, imageops::FilterType};
|
||||
/**
|
||||
@@ -458,7 +457,6 @@ impl From<PortThumbnailSize> for ThumbnailSize {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ThumbnailPort for ThumbnailService {
|
||||
fn is_supported_image(&self, mime_type: &str) -> bool {
|
||||
ThumbnailService::is_supported_image(mime_type)
|
||||
|
||||
@@ -5,6 +5,7 @@ use tracing::{debug, error, info, instrument};
|
||||
|
||||
use crate::common::errors::Result;
|
||||
use crate::domain::repositories::trash_repository::TrashRepository;
|
||||
use crate::infrastructure::repositories::pg::trash_db_repository::TrashDbRepository;
|
||||
|
||||
/// Service for automatic cleanup of expired items in the trash.
|
||||
///
|
||||
@@ -12,12 +13,12 @@ use crate::domain::repositories::trash_repository::TrashRepository;
|
||||
/// in **2 SQL statements inside a single transaction**, instead of the
|
||||
/// previous N+1 pattern that issued 3 queries per expired item.
|
||||
pub struct TrashCleanupService {
|
||||
trash_repository: Arc<dyn TrashRepository>,
|
||||
trash_repository: Arc<TrashDbRepository>,
|
||||
cleanup_interval_hours: u64,
|
||||
}
|
||||
|
||||
impl TrashCleanupService {
|
||||
pub fn new(trash_repository: Arc<dyn TrashRepository>, cleanup_interval_hours: u64) -> Self {
|
||||
pub fn new(trash_repository: Arc<TrashDbRepository>, cleanup_interval_hours: u64) -> Self {
|
||||
Self {
|
||||
trash_repository,
|
||||
cleanup_interval_hours: cleanup_interval_hours.max(1), // Minimum 1 hour
|
||||
@@ -57,7 +58,7 @@ impl TrashCleanupService {
|
||||
|
||||
/// Bulk-delete all expired trash items in a single transaction.
|
||||
#[instrument(skip(trash_repository))]
|
||||
async fn cleanup_expired_items(trash_repository: Arc<dyn TrashRepository>) -> Result<()> {
|
||||
async fn cleanup_expired_items(trash_repository: Arc<TrashDbRepository>) -> Result<()> {
|
||||
debug!("Starting bulk cleanup of expired trash items");
|
||||
|
||||
let (files, folders) = trash_repository.delete_expired_bulk().await?;
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::{
|
||||
application::ports::zip_ports::ZipPort,
|
||||
common::errors::{DomainError, ErrorKind, Result},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use async_zip::base::write::ZipFileWriter;
|
||||
use async_zip::{Compression, ZipEntryBuilder};
|
||||
use futures::StreamExt;
|
||||
@@ -17,6 +16,8 @@ use thiserror::Error;
|
||||
use tokio::io::BufWriter;
|
||||
use tokio_util::compat::Compat;
|
||||
use tracing::*;
|
||||
use crate::application::services::file_retrieval_service::FileRetrievalService;
|
||||
use crate::application::services::folder_service::FolderService;
|
||||
|
||||
/// Error related to ZIP file creation
|
||||
#[derive(Debug, Error)]
|
||||
@@ -53,15 +54,15 @@ type AsyncZipWriter = ZipFileWriter<Compat<BufWriter<tokio::fs::File>>>;
|
||||
/// `tokio::io::BufWriter` → `tokio::fs::File`, so **no Tokio worker is ever
|
||||
/// blocked** by disk I/O or compression.
|
||||
pub struct ZipService {
|
||||
file_service: Arc<dyn FileRetrievalUseCase>,
|
||||
folder_service: Arc<dyn FolderUseCase>,
|
||||
file_service: Arc<FileRetrievalService>,
|
||||
folder_service: Arc<FolderService>,
|
||||
}
|
||||
|
||||
impl ZipService {
|
||||
/// Creates a new instance of the ZIP service
|
||||
pub fn new(
|
||||
file_service: Arc<dyn FileRetrievalUseCase>,
|
||||
folder_service: Arc<dyn FolderUseCase>,
|
||||
file_service: Arc<FileRetrievalService>,
|
||||
folder_service: Arc<FolderService>,
|
||||
) -> Self {
|
||||
Self {
|
||||
file_service,
|
||||
@@ -239,7 +240,6 @@ impl ZipService {
|
||||
|
||||
// ─── Port implementation ─────────────────────────────────────────────────────
|
||||
|
||||
#[async_trait]
|
||||
impl ZipPort for ZipService {
|
||||
async fn create_folder_zip(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user