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

@@ -4,7 +4,6 @@ use actix_web::{web::Data, HttpResponse};
use rustical_store::model::Addressbook;
use rustical_store::{auth::User, AddressbookStore};
use serde::{Deserialize, Serialize};
use tokio::sync::RwLock;
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
@@ -38,7 +37,7 @@ pub async fn route_mkcol<AS: AddressbookStore + ?Sized>(
path: Path<(String, String)>,
body: String,
user: User,
store: Data<RwLock<AS>>,
store: Data<AS>,
) -> Result<HttpResponse, Error> {
let (principal, addressbook_id) = path.into_inner();
if principal != user.id {
@@ -57,12 +56,7 @@ pub async fn route_mkcol<AS: AddressbookStore + ?Sized>(
synctoken: 0,
};
match store
.read()
.await
.get_addressbook(&principal, &addressbook_id)
.await
{
match store.get_addressbook(&principal, &addressbook_id).await {
Err(rustical_store::Error::NotFound) => {
// No conflict, no worries
}
@@ -76,7 +70,7 @@ pub async fn route_mkcol<AS: AddressbookStore + ?Sized>(
}
}
match store.write().await.insert_addressbook(addressbook).await {
match store.insert_addressbook(addressbook).await {
// TODO: The spec says we should return a mkcol-response.
// However, it works without one but breaks on iPadOS when using an empty one :)
Ok(()) => Ok(HttpResponse::Created()