DAV storage methods

This commit is contained in:
mdecimus
2025-03-06 18:35:46 +01:00
parent 3554dea4cb
commit eadd36f4cb
35 changed files with 1289 additions and 206 deletions

View File

@@ -31,7 +31,7 @@ use store::{
BlobClass,
query::Filter,
rand::{Rng, rng},
write::{Archive, BatchBuilder, BlobOp, assert::HashedValue, log::ChangeLogBuilder},
write::{Archive, BatchBuilder, assert::HashedValue, log::ChangeLogBuilder},
};
use trc::AddContext;
@@ -100,27 +100,13 @@ impl SieveScriptSet for Server {
let blob_size = sieve.size as usize;
let blob_hash = sieve.blob_hash.clone();
// Increment tenant quota
#[cfg(feature = "enterprise")]
if self.core.is_enterprise_edition() {
if let Some(tenant) = ctx.resource_token.tenant {
builder.set_tenant_id(tenant.id);
}
}
// Write record
let mut batch = BatchBuilder::new();
batch
.with_account_id(account_id)
.with_collection(Collection::SieveScript)
.create_document()
.set(
BlobOp::Link {
hash: blob_hash.clone(),
},
Vec::new(),
)
.custom(builder)
.custom(builder.with_tenant_id(&ctx.resource_token))
.caused_by(trc::location!())?;
let document_id = self
@@ -194,7 +180,6 @@ impl SieveScriptSet for Server {
let sieve = sieve
.into_deserialized::<SieveScript>()
.caused_by(trc::location!())?;
let prev_blob_hash = sieve.inner.blob_hash.clone();
match self
.sieve_set_item(
@@ -217,38 +202,16 @@ impl SieveScriptSet for Server {
// Store blob
let sieve = &mut builder.changes_mut().unwrap();
sieve.blob_hash = self.put_blob(account_id, &blob, false).await?.hash;
let blob_hash = sieve.blob_hash.clone();
let blob_size = sieve.size as usize;
// Update tenant quota
#[cfg(feature = "enterprise")]
if self.core.is_enterprise_edition() {
if let Some(tenant) = ctx.resource_token.tenant {
builder.set_tenant_id(tenant.id);
}
}
// Update blobId
batch
.clear(BlobOp::Link {
hash: prev_blob_hash,
})
.set(
BlobOp::Link {
hash: blob_hash.clone(),
},
Vec::new(),
);
BlobId {
hash: blob_hash,
hash: sieve.blob_hash.clone(),
class: BlobClass::Linked {
account_id,
collection: Collection::SieveScript.into(),
document_id,
},
section: BlobSection {
size: blob_size,
size: sieve.size as usize,
..Default::default()
}
.into(),
@@ -259,7 +222,9 @@ impl SieveScriptSet for Server {
};
// Write record
batch.custom(builder).caused_by(trc::location!())?;
batch
.custom(builder.with_tenant_id(&ctx.resource_token))
.caused_by(trc::location!())?;
if !batch.is_empty() {
changes.log_update(Collection::SieveScript, document_id);

View File

@@ -26,7 +26,7 @@ use mail_builder::MessageBuilder;
use mail_parser::decoders::html::html_to_text;
use std::future::Future;
use store::write::{
Archive, BatchBuilder, BlobOp,
Archive, BatchBuilder,
assert::HashedValue,
log::{Changes, LogInsert},
};
@@ -255,7 +255,8 @@ impl VacationResponseSet for Server {
let mut obj = ObjectIndexBuilder::new()
.with_current_opt(prev_sieve)
.with_changes(sieve);
.with_changes(sieve)
.with_tenant_id(&resource_token);
// Update id
if let Some(document_id) = document_id {
@@ -270,7 +271,7 @@ impl VacationResponseSet for Server {
// Create sieve script only if there are changes
if build_script {
// Upload new blob
let hash = self
obj.changes_mut().unwrap().blob_hash = self
.put_blob(
account_id,
&self.build_script(obj.changes_mut().unwrap())?,
@@ -278,31 +279,6 @@ impl VacationResponseSet for Server {
)
.await?
.hash;
let sieve = &mut obj.changes_mut().unwrap();
sieve.blob_hash = hash;
// Link blob
batch.set(
BlobOp::Link {
hash: sieve.blob_hash.clone(),
},
Vec::new(),
);
// Unlink previous blob
if let Some(current) = obj.current() {
batch.clear(BlobOp::Link {
hash: current.inner.blob_hash.clone(),
});
}
// Update tenant quota
#[cfg(feature = "enterprise")]
if self.core.is_enterprise_edition() {
if let Some(tenant) = resource_token.tenant {
obj.set_tenant_id(tenant.id);
}
}
};
// Write changes