Files
Oxicloud/src/application/ports/music_ports.rs
T
Claude 12dc648cff perf: round 4 — one-pass row paths, drive-selector cache, CalDAV single-parse, streamed Azure, batched hydration
Nine benchmark-gated changes (benches/ROUND4.md; every one ships with a
BEFORE/AFTER bench + equivalence gate, rollback rule as ROUND2/3):

- Row→entity path build: one-pass StoragePath::from_folder_and_name /
  from_joined + normalize_storage_name_owned + alloc-free Display —
  743→417 ns/file-row (1.78x), −5 allocs/row on every listing surface.
- WebDAV drive-selector: per-user readable_cache (single-flight, 30 s
  TTL, explicit invalidation incl. membership + group changes) replaces
  the grants join per request — 441 µs → 0.8 µs (~550x), 0 queries warm.
- CalDAV from_ical/update_ical_data: 8 full IcalParser runs per VEVENT
  → 1 (7.1x per PUT, 4.4x on 50-event imports); alloc-free split_vevents,
  chunk scan without the whole-body uppercase copy (1.4x), borrowed-key
  UID grouping (1.3x), REPORT props no longer cloned.
- PROPFIND emit: partition Vecs dropped (single-pass 404 list) + stack
  rendered RFC 3339/2822 dates, sizes, quoted etags (common::fmt,
  chrono-byte-identical, sweep-tested) on both DAV surfaces — 1.22x
  per page, 17.9→12.0 allocs/row.
- Grant-listing hydration: calendars/address books/playlists batch
  hydrate via = ANY($1) — 15 serial queries → 1 (~13x per sync poll).
- user-flags cache: get→insert → try_get_with single-flight (32→1
  queries per cold herd).
- Azure downloads: whole-blob Vec buffering → streamed SDK pages —
  TTFB 349→4 ms (87x), peak heap 480→1.9 MiB (254x) on 256 MiB blobs;
  new OXICLOUD_AZURE_ENDPOINT_URL override (Azurite/bench hook).
- Face indexing: unbounded per-image tokio::spawn → core-count
  semaphore, permit before blob read — peak heap 1175→176 MiB (6.7x).

Checks: cargo fmt, clippy --all-features --all-targets -D warnings,
cargo test --workspace (523 passed) + --features test_utils. hurl API
suite and dockerized integration DB not runnable in this environment —
left to CI.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017aJu9ghvuT8WqC31ZEGTBA
2026-07-17 13:48:37 +00:00

164 lines
4.5 KiB
Rust

use crate::application::dtos::playlist_dto::{
AddTracksDto, AudioMetadataDto, CreatePlaylistDto, PlaylistDto, PlaylistItemDto,
PlaylistQueryDto, PlaylistShareInfoDto, ReorderTracksDto, SharePlaylistDto, UpdatePlaylistDto,
};
use crate::common::errors::DomainError;
use uuid::Uuid;
pub trait MusicUseCase: Send + Sync {
async fn create_playlist(
&self,
dto: CreatePlaylistDto,
user_id: Uuid,
) -> Result<PlaylistDto, DomainError>;
async fn update_playlist(
&self,
playlist_id: &str,
dto: UpdatePlaylistDto,
user_id: Uuid,
) -> Result<PlaylistDto, DomainError>;
async fn delete_playlist(&self, playlist_id: &str, user_id: Uuid) -> Result<(), DomainError>;
async fn get_playlist(
&self,
playlist_id: &str,
user_id: Uuid,
) -> Result<PlaylistDto, DomainError>;
async fn list_playlists(
&self,
query: PlaylistQueryDto,
user_id: Uuid,
) -> Result<Vec<PlaylistDto>, DomainError>;
async fn add_tracks(
&self,
playlist_id: &str,
dto: AddTracksDto,
user_id: Uuid,
) -> Result<Vec<PlaylistItemDto>, DomainError>;
async fn remove_track(
&self,
playlist_id: &str,
file_id: &str,
user_id: Uuid,
) -> Result<(), DomainError>;
async fn reorder_tracks(
&self,
playlist_id: &str,
dto: ReorderTracksDto,
user_id: Uuid,
) -> Result<(), DomainError>;
async fn list_playlist_tracks(
&self,
playlist_id: &str,
user_id: Uuid,
) -> Result<Vec<PlaylistItemDto>, DomainError>;
async fn share_playlist(
&self,
playlist_id: &str,
dto: SharePlaylistDto,
caller_id: Uuid,
) -> Result<(), DomainError>;
async fn remove_share(
&self,
playlist_id: &str,
target_user_id: &str,
caller_id: Uuid,
) -> Result<(), DomainError>;
async fn get_playlist_shares(
&self,
playlist_id: &str,
user_id: Uuid,
) -> Result<Vec<PlaylistShareInfoDto>, DomainError>;
async fn get_audio_metadata(
&self,
file_id: &str,
user_id: Uuid,
) -> Result<Option<AudioMetadataDto>, DomainError>;
}
pub trait MusicStoragePort: Send + Sync {
async fn create_playlist(
&self,
dto: CreatePlaylistDto,
user_id: Uuid,
) -> Result<PlaylistDto, DomainError>;
async fn update_playlist(
&self,
playlist_id: &str,
dto: UpdatePlaylistDto,
) -> Result<PlaylistDto, DomainError>;
async fn delete_playlist(&self, playlist_id: &str) -> Result<(), DomainError>;
async fn get_playlist(&self, playlist_id: &str) -> Result<Option<PlaylistDto>, DomainError>;
/// Batch sibling of [`Self::get_playlist`]: hydrate a page of
/// grant-derived ids in ONE storage round-trip. Missing rows drop
/// out silently; ordering is not guaranteed.
async fn get_playlists_by_ids(&self, ids: &[Uuid]) -> Result<Vec<PlaylistDto>, DomainError>;
async fn list_playlists_by_owner(
&self,
owner_id: Uuid,
) -> Result<Vec<PlaylistDto>, DomainError>;
async fn list_shared_with_user(&self, user_id: Uuid) -> Result<Vec<PlaylistDto>, DomainError>;
async fn list_public_playlists(
&self,
limit: i64,
offset: i64,
) -> Result<Vec<PlaylistDto>, DomainError>;
async fn user_has_access(&self, playlist_id: &str, user_id: Uuid) -> Result<bool, DomainError>;
async fn user_can_write(&self, playlist_id: &str, user_id: Uuid) -> Result<bool, DomainError>;
async fn add_tracks(
&self,
playlist_id: &Uuid,
file_ids: &[Uuid],
) -> Result<Vec<PlaylistItemDto>, DomainError>;
async fn remove_track(&self, playlist_id: &Uuid, file_id: &Uuid) -> Result<(), DomainError>;
async fn reorder_tracks(
&self,
playlist_id: &Uuid,
item_ids: &[Uuid],
) -> Result<(), DomainError>;
async fn list_playlist_tracks(
&self,
playlist_id: &Uuid,
) -> Result<Vec<PlaylistItemDto>, DomainError>;
async fn share_playlist(
&self,
playlist_id: &Uuid,
user_id: Uuid,
can_write: bool,
) -> Result<(), DomainError>;
async fn remove_share(&self, playlist_id: &Uuid, user_id: Uuid) -> Result<(), DomainError>;
async fn get_shares(&self, playlist_id: &Uuid) -> Result<Vec<(Uuid, bool)>, DomainError>;
async fn get_audio_metadata(
&self,
file_id: &Uuid,
) -> Result<Option<AudioMetadataDto>, DomainError>;
}