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()
|
||||
|
||||
@@ -18,7 +18,6 @@ use rustical_dav::{
|
||||
};
|
||||
use rustical_store::{model::AddressObject, AddressbookStore};
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
@@ -34,7 +33,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore + ?Sized>(
|
||||
principal_url: &str,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
store: &RwLock<AS>,
|
||||
store: &AS,
|
||||
) -> Result<(Vec<AddressObject>, Vec<String>), Error> {
|
||||
let resource_def =
|
||||
ResourceDef::prefix(principal_url).join(&ResourceDef::new("/{addressbook_id}/{object_id}"));
|
||||
@@ -42,7 +41,6 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore + ?Sized>(
|
||||
let mut result = vec![];
|
||||
let mut not_found = vec![];
|
||||
|
||||
let store = store.read().await;
|
||||
for href in &addressbook_multiget.href {
|
||||
let mut path = Path::new(href.as_str());
|
||||
if !resource_def.capture_match_info(&mut path) {
|
||||
@@ -68,7 +66,7 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore + ?Sized>(
|
||||
req: HttpRequest,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
addr_store: &RwLock<AS>,
|
||||
addr_store: &AS,
|
||||
) -> Result<MultistatusElement<PropstatWrapper<AddressObjectProp>, String>, Error> {
|
||||
let principal_url = PrincipalResource::get_url(req.resource_map(), vec![principal]).unwrap();
|
||||
let (objects, not_found) = get_objects_addressbook_multiget(
|
||||
|
||||
@@ -7,7 +7,6 @@ use addressbook_multiget::{handle_addressbook_multiget, AddressbookMultigetReque
|
||||
use rustical_store::{auth::User, AddressbookStore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sync_collection::{handle_sync_collection, SyncCollectionRequest};
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::instrument;
|
||||
|
||||
mod addressbook_multiget;
|
||||
@@ -34,7 +33,7 @@ pub async fn route_report_addressbook<AS: AddressbookStore + ?Sized>(
|
||||
body: String,
|
||||
user: User,
|
||||
req: HttpRequest,
|
||||
addr_store: Data<RwLock<AS>>,
|
||||
addr_store: Data<AS>,
|
||||
) -> Result<impl Responder, Error> {
|
||||
let (principal, addressbook_id) = path.into_inner();
|
||||
if principal != user.id {
|
||||
@@ -50,7 +49,7 @@ pub async fn route_report_addressbook<AS: AddressbookStore + ?Sized>(
|
||||
req,
|
||||
&principal,
|
||||
&addressbook_id,
|
||||
&addr_store,
|
||||
addr_store.as_ref(),
|
||||
)
|
||||
.await?
|
||||
}
|
||||
@@ -60,7 +59,7 @@ pub async fn route_report_addressbook<AS: AddressbookStore + ?Sized>(
|
||||
req,
|
||||
&principal,
|
||||
&addressbook_id,
|
||||
&addr_store,
|
||||
addr_store.as_ref(),
|
||||
)
|
||||
.await?
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ use rustical_store::{
|
||||
AddressbookStore,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
@@ -45,7 +44,7 @@ pub async fn handle_sync_collection<AS: AddressbookStore + ?Sized>(
|
||||
req: HttpRequest,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
addr_store: &RwLock<AS>,
|
||||
addr_store: &AS,
|
||||
) -> Result<MultistatusElement<PropstatWrapper<AddressObjectProp>, String>, Error> {
|
||||
let props = match sync_collection.prop {
|
||||
PropfindType::Allprop => {
|
||||
@@ -60,8 +59,6 @@ pub async fn handle_sync_collection<AS: AddressbookStore + ?Sized>(
|
||||
|
||||
let old_synctoken = parse_synctoken(&sync_collection.sync_token).unwrap_or(0);
|
||||
let (new_objects, deleted_objects, new_synctoken) = addr_store
|
||||
.read()
|
||||
.await
|
||||
.sync_changes(principal, addressbook_id, old_synctoken)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user