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
This commit is contained in:
@@ -53,6 +53,16 @@ pub trait CalendarEventRepository: Send + Sync + 'static {
|
||||
ical_uid: &str,
|
||||
) -> CalendarEventRepositoryResult<Option<CalendarEvent>>;
|
||||
|
||||
/// Finds the events matching any of the given iCalendar UIDs in one
|
||||
/// indexed query (`ical_uid = ANY(...)`). Used by CalDAV multiget so a
|
||||
/// request for a handful of events never pays for the whole calendar.
|
||||
/// UIDs with no matching event are silently absent from the result.
|
||||
async fn find_events_by_ical_uids(
|
||||
&self,
|
||||
calendar_id: &Uuid,
|
||||
ical_uids: &[String],
|
||||
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
|
||||
|
||||
/// Counts events in a calendar
|
||||
async fn count_events_in_calendar(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user