Files
Oxicloud/src/domain/repositories/contact_repository.rs
T
Claude 6a27c742d4 Fix CalDAV/CardDAV multiget loading entire collections into memory
A REPORT multiget for a handful of resources previously listed the
whole calendar/address book (every row incl. ical_data/vcard) and
filtered by href in Rust with an O(N×M) substring scan. Large
collections paid full-table latency, RAM and DB CPU on every sync.

- Add find_events_by_ical_uids / get_contacts_by_uids through every
  layer (domain repo trait → PG repo → storage port/adapter → use case
  → handler) using one indexed `= ANY($2)` query, mirroring the
  existing single-UID lookups.
- Extract UIDs from multiget hrefs with a shared, tested
  uid_from_multiget_href helper (percent-decoding, case-insensitive
  extension strip, collection hrefs rejected). Exact UID matching also
  removes the false positives the old substring filter allowed.
- CalDAV PROPFIND single-event path now uses the existing indexed
  get_event_by_ical_uid instead of listing all events.
- Honour the already-documented limit/offset query params on
  GET /api/address-books/{id}/contacts: optional ListQuery fields
  thread through ContactUseCase::list_contacts to a paginated repo
  query. Omitted params keep returning the full book (frontend and
  DAV listing/sync paths unchanged).

https://claude.ai/code/session_0193Hff42gaA962wThxMGSd1
2026-06-11 09:21:35 +00:00

76 lines
3.0 KiB
Rust

use std::result::Result;
use uuid::Uuid;
use crate::common::errors::DomainError;
use crate::domain::entities::contact::{Contact, ContactGroup};
pub type ContactRepositoryResult<T> = Result<T, DomainError>;
pub trait ContactRepository: Send + Sync + 'static {
async fn create_contact(&self, contact: Contact) -> ContactRepositoryResult<Contact>;
async fn update_contact(&self, contact: Contact) -> ContactRepositoryResult<Contact>;
async fn delete_contact(&self, id: &Uuid) -> ContactRepositoryResult<()>;
async fn get_contact_by_id(&self, id: &Uuid) -> ContactRepositoryResult<Option<Contact>>;
async fn get_contact_by_uid(
&self,
address_book_id: &Uuid,
uid: &str,
) -> ContactRepositoryResult<Option<Contact>>;
/// Fetches the contacts matching any of the given vCard UIDs in one
/// indexed query (`uid = ANY(...)`). Used by CardDAV multiget so a
/// request for a handful of contacts never pays for the whole book.
/// UIDs with no matching contact are silently absent from the result.
async fn get_contacts_by_uids(
&self,
address_book_id: &Uuid,
uids: &[String],
) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contacts_by_address_book(
&self,
address_book_id: &Uuid,
) -> ContactRepositoryResult<Vec<Contact>>;
/// Same as [`Self::get_contacts_by_address_book`] but bounded by
/// `LIMIT`/`OFFSET` for paginated listings.
async fn get_contacts_by_address_book_paginated(
&self,
address_book_id: &Uuid,
limit: i64,
offset: i64,
) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contacts_by_email(&self, email: &str) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contacts_by_group(&self, group_id: &Uuid)
-> ContactRepositoryResult<Vec<Contact>>;
async fn search_contacts(
&self,
address_book_id: &Uuid,
query: &str,
) -> ContactRepositoryResult<Vec<Contact>>;
}
pub trait ContactGroupRepository: Send + Sync + 'static {
async fn create_group(&self, group: ContactGroup) -> ContactRepositoryResult<ContactGroup>;
async fn update_group(&self, group: ContactGroup) -> ContactRepositoryResult<ContactGroup>;
async fn delete_group(&self, id: &Uuid) -> ContactRepositoryResult<()>;
async fn get_group_by_id(&self, id: &Uuid) -> ContactRepositoryResult<Option<ContactGroup>>;
async fn get_groups_by_address_book(
&self,
address_book_id: &Uuid,
) -> ContactRepositoryResult<Vec<ContactGroup>>;
async fn add_contact_to_group(
&self,
group_id: &Uuid,
contact_id: &Uuid,
) -> ContactRepositoryResult<()>;
async fn remove_contact_from_group(
&self,
group_id: &Uuid,
contact_id: &Uuid,
) -> ContactRepositoryResult<()>;
async fn get_contacts_in_group(&self, group_id: &Uuid)
-> ContactRepositoryResult<Vec<Contact>>;
async fn get_groups_for_contact(
&self,
contact_id: &Uuid,
) -> ContactRepositoryResult<Vec<ContactGroup>>;
}