Files
Oxicloud/src/domain/repositories/calendar_event_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

94 lines
3.1 KiB
Rust

use crate::common::errors::DomainError;
use crate::domain::entities::calendar_event::CalendarEvent;
use chrono::{DateTime, Utc};
use uuid::Uuid;
pub type CalendarEventRepositoryResult<T> = Result<T, DomainError>;
/// Repository interface for CalendarEvent entity operations
pub trait CalendarEventRepository: Send + Sync + 'static {
/// Creates a new calendar event
async fn create_event(
&self,
event: CalendarEvent,
) -> CalendarEventRepositoryResult<CalendarEvent>;
/// Updates an existing calendar event
async fn update_event(
&self,
event: CalendarEvent,
) -> CalendarEventRepositoryResult<CalendarEvent>;
/// Deletes a calendar event by ID
async fn delete_event(&self, id: &Uuid) -> CalendarEventRepositoryResult<()>;
/// Finds a calendar event by its ID
async fn find_event_by_id(&self, id: &Uuid) -> CalendarEventRepositoryResult<CalendarEvent>;
/// Lists all events in a specific calendar
async fn list_events_by_calendar(
&self,
calendar_id: &Uuid,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Finds events in a calendar by their summary/title (partial match)
async fn find_events_by_summary(
&self,
calendar_id: &Uuid,
summary: &str,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Gets events in a specific time range for a calendar
async fn get_events_in_time_range(
&self,
calendar_id: &Uuid,
start: &DateTime<Utc>,
end: &DateTime<Utc>,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Finds an event by its iCalendar UID in a specific calendar
async fn find_event_by_ical_uid(
&self,
calendar_id: &Uuid,
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,
calendar_id: &Uuid,
) -> CalendarEventRepositoryResult<i64>;
/// Deletes all events in a calendar
async fn delete_all_events_in_calendar(
&self,
calendar_id: &Uuid,
) -> CalendarEventRepositoryResult<i64>;
/// Lists events by calendar with pagination
async fn list_events_by_calendar_paginated(
&self,
calendar_id: &Uuid,
limit: i64,
offset: i64,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Finds events with recurrence rules that might occur in a time range
async fn find_recurring_events_in_range(
&self,
calendar_id: &Uuid,
start: &DateTime<Utc>,
end: &DateTime<Utc>,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
}