Incremental caching - tests passing

This commit is contained in:
mdecimus
2025-04-10 20:42:51 +02:00
parent b396341240
commit 15651c26a1
28 changed files with 522 additions and 457 deletions

View File

@@ -16,7 +16,10 @@ use common::{
use compact_str::CompactString;
use directory::{QueryBy, backend::internal::PrincipalField};
use email::{
mailbox::{INBOX_ID, cache::MessageMailboxCache},
mailbox::{
INBOX_ID,
cache::{MailboxCacheAccess, MessageMailboxCache},
},
message::cache::{MessageCache, MessageCacheAccess},
};
use imap_proto::protocol::list::Attribute;
@@ -114,10 +117,8 @@ impl<T: SessionStream> SessionData<T> {
{
None
} else {
self.server
.shared_containers(access_token, account_id, Collection::Mailbox, Acl::Read)
.await
.caused_by(trc::location!())?
cached_mailboxes
.shared_mailboxes(access_token, Acl::Read)
.into()
};
@@ -179,11 +180,10 @@ impl<T: SessionStream> SessionData<T> {
account.mailbox_state.insert(
mailbox_id,
Mailbox {
has_children: cached_mailboxes.items.values().any(|child| {
child
.parent_id
.is_some_and(|parent_id| parent_id == mailbox_id)
}),
has_children: cached_mailboxes
.items
.values()
.any(|child| child.parent_id == mailbox_id),
is_subscribed: mailbox.subscribers.contains(&access_token.primary_id()),
special_use: match mailbox.role {
SpecialUse::Trash => Some(Attribute::Trash),

View File

@@ -16,13 +16,14 @@ use common::{
};
use compact_str::CompactString;
use directory::Permission;
use email::mailbox::cache::{MailboxCacheAccess, MessageMailboxCache};
use imap_proto::{
Command, ResponseCode, StatusResponse,
protocol::{create::Arguments, list::Attribute},
receiver::Request,
};
use jmap_proto::types::{acl::Acl, collection::Collection, id::Id, property::Property};
use store::{query::Filter, write::BatchBuilder};
use jmap_proto::types::{acl::Acl, collection::Collection, id::Id};
use store::write::BatchBuilder;
use trc::AddContext;
impl<T: SessionStream> Session<T> {
@@ -280,23 +281,21 @@ impl<T: SessionStream> SessionData<T> {
parent_mailbox_name,
special_use: if let Some(mailbox_role) = mailbox_role {
// Make sure role is unique
let role_name = attr_to_role(mailbox_role).as_str().unwrap_or_default();
if !self
let special_use = attr_to_role(mailbox_role);
if self
.server
.store()
.filter(
account_id,
Collection::Mailbox,
vec![Filter::eq(Property::Role, role_name.as_bytes().to_vec())],
)
.get_cached_mailboxes(account_id)
.await
.caused_by(trc::location!())?
.results
.is_empty()
.by_role(&special_use)
.is_some()
{
return Err(trc::ImapEvent::Error
.into_err()
.details(format!("A mailbox with role '{role_name}' already exists.",))
.details(format!(
"A mailbox with role '{}' already exists.",
special_use.as_str().unwrap_or_default()
))
.code(ResponseCode::UseAttr));
}
Some(mailbox_role)