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")?;
|
||||
|
||||
Reference in New Issue
Block a user