mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Remove RwLock around stores, locking shall be the responsibility of the store implementation
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user