Remove RwLock around stores, locking shall be the responsibility of the store implementation

This commit is contained in:
Lennart
2024-10-27 15:36:49 +01:00
parent df8790f46d
commit 858f43de67
31 changed files with 119 additions and 236 deletions

View File

@@ -6,12 +6,11 @@ use rustical_frontend::configure_frontend;
use rustical_store::auth::AuthenticationProvider;
use rustical_store::{AddressbookStore, CalendarStore};
use std::sync::Arc;
use tokio::sync::RwLock;
use tracing_actix_web::TracingLogger;
pub fn make_app<AS: AddressbookStore + ?Sized, CS: CalendarStore + ?Sized>(
addr_store: Arc<RwLock<AS>>,
cal_store: Arc<RwLock<CS>>,
addr_store: Arc<AS>,
cal_store: Arc<CS>,
auth_provider: Arc<impl AuthenticationProvider>,
) -> App<
impl ServiceFactory<

View File

@@ -19,7 +19,6 @@ use rustical_store::{AddressbookStore, CalendarStore};
use std::fs;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;
use tracing::level_filters::LevelFilter;
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::layer::SubscriberExt;
@@ -41,14 +40,11 @@ struct Args {
async fn get_data_stores(
migrate: bool,
config: &DataStoreConfig,
) -> Result<(
Arc<RwLock<dyn AddressbookStore>>,
Arc<RwLock<dyn CalendarStore>>,
)> {
) -> Result<(Arc<dyn AddressbookStore>, Arc<dyn CalendarStore>)> {
Ok(match &config {
DataStoreConfig::Sqlite(SqliteDataStoreConfig { db_url }) => {
let db = create_db_pool(db_url, migrate).await?;
let sqlite_store = Arc::new(RwLock::new(SqliteStore::new(db)));
let sqlite_store = Arc::new(SqliteStore::new(db));
(sqlite_store.clone(), sqlite_store.clone())
}
})