perf: round 11 — StoragePath joined-only, classifier fusion, memoized bodies, query-shape pack, SPA fine-grained stars
Backend (each change benchmark-gated with BEFORE replicas + equivalence gates; see examples/bench_round11_micro.rs, bench_round11_queries.rs, bench_log_writer.rs and benches/ROUND11.md — final numbers land in the follow-up doc commit): - StoragePath re-representation: single canonical joined String, segments derived on demand; File/Folder drop the duplicated path_string field (4000→1000 allocs per 500-row listing page) - Display classifier fusion: classify_display shares one stack-lowered extension across the three decision trees; call sites in FileDto, folder/favorites/recent handlers, trash, path-resolver (+ interning where Arc::from was still used) - /status.php and /openapi.json memoized into OnceLock<Bytes> (openapi rebuilt a 171 KiB spec per request: 2.8 ms → 18 ns) - NC upload-session PROPFIND: write! + pre-sized body + stack RFC2822 dates (2.3-2.6x, 2582→772 allocs at 256 chunks) - REST download: dead FileDto clone removed (capture mime/size + move) - CalendarEventDto/TrashedItem into_parts moves (11 KiB ical_data memcpy gone per CalDAV row); CardDAV getlastmodified stack render - 4xx path: borrowed ErrorResponse serialize, ErrorKind::as_str, not_found/already_exists clone kill - vCard emit via write!; search page moved out with into_iter skip/take; content-hit UUIDs parsed once; group last-user check via HashSet - RateLimiter: lock-free get + insert (and_upsert_with variant REJECTED by benchmark); CSRF token borrow-compare + borrowed cookie extraction - Thumbnail/preview ETags built from as_str (Debug-identical bytes) - Encrypted backend: encrypt_in_place_detached single-buffer write path, chunk-sized reserve in collect_stream; retry labels made lazy - PG: deferred upload registration 3→1 round-trips (persist_file CTE template); direct_grant_cache for Calendar/AddressBook/Playlist authz (single-flight + set_role/clear_role invalidation); expand_user tokio::join!; geo clusters min(uuid)::text; recluster face assignment batched into one UNNEST update - People recluster cosine: norms precomputed once (bit-identical gate) - NC capabilities poll logs demoted to debug; tracing-appender dep added for the log-writer benchmark Frontend: - ResourceList.selectedEntries O(N)-per-toggle → id-index projection O(k log k); favorites/recent consume the batchToolbar snippet param and drop their duplicate filter + dead selectedIds mirror - Recent: star state via new favoriteIds prop — a star click no longer rebuilds all N entries - admin timeAgo >30d fallback uses the cached Intl.DateTimeFormat - vitest gates in src/lib/components/round11.bench.test.ts Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ABhTEHuGujvwoodh67Kga7
This commit is contained in:
@@ -22,6 +22,25 @@ pub use super::entity_errors::CalendarEventError;
|
||||
* Represents a calendar event or appointment that can be synced via CalDAV.
|
||||
* Follows the iCalendar format (RFC 5545) for compatibility with CalDAV clients.
|
||||
*/
|
||||
/// Owned decomposition of a [`CalendarEvent`] (see
|
||||
/// [`CalendarEvent::into_parts`]).
|
||||
pub struct CalendarEventParts {
|
||||
pub id: Uuid,
|
||||
pub calendar_id: Uuid,
|
||||
pub summary: String,
|
||||
pub description: Option<String>,
|
||||
pub location: Option<String>,
|
||||
pub start_time: DateTime<Utc>,
|
||||
pub end_time: DateTime<Utc>,
|
||||
pub all_day: bool,
|
||||
pub rrule: Option<String>,
|
||||
pub recurrence_id: Option<DateTime<Utc>>,
|
||||
pub ical_uid: String,
|
||||
pub ical_data: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CalendarEvent {
|
||||
/// Unique identifier for the event
|
||||
@@ -456,6 +475,30 @@ impl CalendarEvent {
|
||||
&self.updated_at
|
||||
}
|
||||
|
||||
/// Decompose into owned parts for DTO conversion — the `File`/`Folder`/
|
||||
/// `Contact` pattern. Moving the owned `String`s (most importantly the
|
||||
/// unbounded `ical_data` blob, ~11 KB with attendees/VALARMs) replaces
|
||||
/// the per-event deep copies `CalendarEventDto::from` used to make via
|
||||
/// getters (benches/ROUND11.md §19).
|
||||
pub fn into_parts(self) -> CalendarEventParts {
|
||||
CalendarEventParts {
|
||||
id: self.id,
|
||||
calendar_id: self.calendar_id,
|
||||
summary: self.summary,
|
||||
description: self.description,
|
||||
location: self.location,
|
||||
start_time: self.start_time,
|
||||
end_time: self.end_time,
|
||||
all_day: self.all_day,
|
||||
rrule: self.rrule,
|
||||
recurrence_id: self.recurrence_id,
|
||||
ical_uid: self.ical_uid,
|
||||
ical_data: self.ical_data,
|
||||
created_at: self.created_at,
|
||||
updated_at: self.updated_at,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the duration of the event
|
||||
pub fn duration(&self) -> Duration {
|
||||
self.end_time - self.start_time
|
||||
|
||||
@@ -16,7 +16,6 @@ pub struct FileParts {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub storage_path: StoragePath,
|
||||
pub path_string: String,
|
||||
pub size: u64,
|
||||
pub mime_type: String,
|
||||
pub folder_id: Option<String>,
|
||||
@@ -48,12 +47,11 @@ pub struct File {
|
||||
/// Name of the file including extension
|
||||
name: String,
|
||||
|
||||
/// Path to the file in the domain model
|
||||
/// Path to the file in the domain model. Owns the canonical joined
|
||||
/// string; `path_string()` borrows it (the separate duplicate field
|
||||
/// was removed in ROUND11 §20 along with per-segment allocations).
|
||||
storage_path: StoragePath,
|
||||
|
||||
/// String representation of the path for API compatibility
|
||||
path_string: String,
|
||||
|
||||
/// Size of the file in bytes
|
||||
size: u64,
|
||||
|
||||
@@ -99,7 +97,6 @@ impl Default for File {
|
||||
id: "stub-id".to_string(),
|
||||
name: "stub-file.txt".to_string(),
|
||||
storage_path: StoragePath::from_string("/"),
|
||||
path_string: "/".to_string(),
|
||||
size: 0,
|
||||
mime_type: "application/octet-stream".to_string(),
|
||||
folder_id: None,
|
||||
@@ -132,14 +129,10 @@ impl File {
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
// Store the path string for serialization compatibility
|
||||
let path_string = storage_path.to_path_string();
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
size,
|
||||
mime_type,
|
||||
folder_id,
|
||||
@@ -165,14 +158,10 @@ impl File {
|
||||
return Err(FileError::InvalidFileName(format!("{name}: {reason}")));
|
||||
}
|
||||
|
||||
// Store the path string for serialization compatibility
|
||||
let path_string = storage_path.to_path_string();
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
size: 0, // Folders have zero size
|
||||
mime_type: "directory".to_string(), // Standard MIME type for directories
|
||||
folder_id: parent_id,
|
||||
@@ -257,14 +246,10 @@ impl File {
|
||||
return Err(FileError::InvalidFileName(format!("{name}: {reason}")));
|
||||
}
|
||||
|
||||
// Store the path string for serialization compatibility
|
||||
let path_string = storage_path.to_path_string();
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
size,
|
||||
mime_type,
|
||||
folder_id,
|
||||
@@ -304,7 +289,7 @@ impl File {
|
||||
created_by: Option<Uuid>,
|
||||
updated_by: Option<Uuid>,
|
||||
) -> FileResult<Self> {
|
||||
let (storage_path, path_string) = StoragePath::from_folder_and_name(folder_path, &name);
|
||||
let storage_path = StoragePath::from_folder_and_name(folder_path, &name);
|
||||
|
||||
let name = normalize_storage_name_owned(name);
|
||||
if let Err(reason) = validate_storage_name(&name) {
|
||||
@@ -315,7 +300,6 @@ impl File {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
size,
|
||||
mime_type,
|
||||
folder_id,
|
||||
@@ -336,7 +320,6 @@ impl File {
|
||||
id: self.id,
|
||||
name: self.name,
|
||||
storage_path: self.storage_path,
|
||||
path_string: self.path_string,
|
||||
size: self.size,
|
||||
mime_type: self.mime_type,
|
||||
folder_id: self.folder_id,
|
||||
@@ -438,7 +421,7 @@ impl File {
|
||||
}
|
||||
|
||||
pub fn path_string(&self) -> &str {
|
||||
&self.path_string
|
||||
self.storage_path.as_str()
|
||||
}
|
||||
|
||||
pub fn size(&self) -> u64 {
|
||||
@@ -487,8 +470,9 @@ impl File {
|
||||
created_at: u64,
|
||||
modified_at: u64,
|
||||
) -> Self {
|
||||
// Create storage_path from string
|
||||
let storage_path = StoragePath::from_string(&path);
|
||||
// Adopt the DTO path (canonical inputs are reused with zero
|
||||
// copies; non-canonical ones are normalized like from_string did).
|
||||
let storage_path = StoragePath::from_joined(path);
|
||||
|
||||
// Create directly without validation to avoid errors in DTO
|
||||
// conversions. Still NFC-normalize so even DTO-reconstructed
|
||||
@@ -499,7 +483,6 @@ impl File {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string: path,
|
||||
size,
|
||||
mime_type,
|
||||
folder_id,
|
||||
@@ -536,7 +519,6 @@ impl File {
|
||||
// Consume `self` and mutate in place — only the path, name and mtime
|
||||
// change; id / mime_type / folder_id / blob_hash are carried over
|
||||
// without the per-field clone the old `&self` builder paid.
|
||||
self.path_string = new_storage_path.to_path_string();
|
||||
self.storage_path = new_storage_path;
|
||||
self.name = new_name;
|
||||
self.modified_at = now;
|
||||
@@ -561,7 +543,6 @@ impl File {
|
||||
.as_secs();
|
||||
|
||||
// Consume `self`: only the path, folder_id and mtime change.
|
||||
self.path_string = new_storage_path.to_path_string();
|
||||
self.storage_path = new_storage_path;
|
||||
self.folder_id = folder_id;
|
||||
self.modified_at = now;
|
||||
|
||||
@@ -17,7 +17,6 @@ pub struct FolderParts {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub storage_path: StoragePath,
|
||||
pub path_string: String,
|
||||
pub parent_id: Option<String>,
|
||||
/// Drive that owns this folder. See [`Folder::drive_id`].
|
||||
pub drive_id: Uuid,
|
||||
@@ -40,12 +39,10 @@ pub struct Folder {
|
||||
/// Name of the folder
|
||||
name: String,
|
||||
|
||||
/// Path to the folder in the domain model
|
||||
/// Path to the folder in the domain model. Owns the canonical joined
|
||||
/// string; `path_string()` borrows it (ROUND11 §20).
|
||||
storage_path: StoragePath,
|
||||
|
||||
/// String representation of the path (for API compatibility)
|
||||
path_string: String,
|
||||
|
||||
/// Parent folder ID (None if it's a root folder)
|
||||
parent_id: Option<String>,
|
||||
|
||||
@@ -94,7 +91,6 @@ impl Default for Folder {
|
||||
id: "stub-id".to_string(),
|
||||
name: "stub-folder".to_string(),
|
||||
storage_path: StoragePath::from_string("/"),
|
||||
path_string: "/".to_string(),
|
||||
parent_id: None,
|
||||
drive_id: Uuid::nil(),
|
||||
created_at: 0,
|
||||
@@ -130,13 +126,10 @@ impl Folder {
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
let path_string = storage_path.to_path_string();
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
parent_id,
|
||||
drive_id: Uuid::nil(),
|
||||
created_at: now,
|
||||
@@ -226,13 +219,10 @@ impl Folder {
|
||||
return Err(FolderError::InvalidFolderName(format!("{name}: {reason}")));
|
||||
}
|
||||
|
||||
let path_string = storage_path.to_path_string();
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
parent_id,
|
||||
drive_id,
|
||||
created_at,
|
||||
@@ -270,13 +260,12 @@ impl Folder {
|
||||
return Err(FolderError::InvalidFolderName(format!("{name}: {reason}")));
|
||||
}
|
||||
|
||||
let (storage_path, path_string) = StoragePath::from_joined(path);
|
||||
let storage_path = StoragePath::from_joined(path);
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string,
|
||||
parent_id,
|
||||
drive_id,
|
||||
created_at,
|
||||
@@ -296,7 +285,6 @@ impl Folder {
|
||||
id: self.id,
|
||||
name: self.name,
|
||||
storage_path: self.storage_path,
|
||||
path_string: self.path_string,
|
||||
parent_id: self.parent_id,
|
||||
drive_id: self.drive_id,
|
||||
created_at: self.created_at,
|
||||
@@ -321,7 +309,7 @@ impl Folder {
|
||||
}
|
||||
|
||||
pub fn path_string(&self) -> &str {
|
||||
&self.path_string
|
||||
self.storage_path.as_str()
|
||||
}
|
||||
|
||||
pub fn parent_id(&self) -> Option<&str> {
|
||||
@@ -445,8 +433,8 @@ impl Folder {
|
||||
created_at: u64,
|
||||
modified_at: u64,
|
||||
) -> Self {
|
||||
// Create storage_path from the string
|
||||
let storage_path = StoragePath::from_string(&path);
|
||||
// Adopt the DTO path (canonical inputs reused with zero copies).
|
||||
let storage_path = StoragePath::from_joined(path);
|
||||
|
||||
// Create directly without validation to avoid errors in DTO
|
||||
// conversions. Still NFC-normalize so DTO-reconstructed
|
||||
@@ -460,7 +448,6 @@ impl Folder {
|
||||
id,
|
||||
name,
|
||||
storage_path,
|
||||
path_string: path,
|
||||
parent_id,
|
||||
// DTO round-trips lose drive_id (FolderDto carries it,
|
||||
// but the legacy `from_dto` signature predates this
|
||||
@@ -495,9 +482,6 @@ impl Folder {
|
||||
None => StoragePath::from_string(&new_name),
|
||||
};
|
||||
|
||||
// Update string representation
|
||||
let new_path_string = new_storage_path.to_path_string();
|
||||
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
@@ -507,7 +491,6 @@ impl Folder {
|
||||
id: self.id.clone(),
|
||||
name: new_name,
|
||||
storage_path: new_storage_path,
|
||||
path_string: new_path_string,
|
||||
parent_id: self.parent_id.clone(),
|
||||
drive_id: self.drive_id,
|
||||
created_at: self.created_at,
|
||||
@@ -535,9 +518,6 @@ impl Folder {
|
||||
None => StoragePath::from_string(&self.name), // Root
|
||||
};
|
||||
|
||||
// Update string representation
|
||||
let new_path_string = new_storage_path.to_path_string();
|
||||
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
@@ -547,7 +527,6 @@ impl Folder {
|
||||
id: self.id.clone(),
|
||||
name: self.name.clone(),
|
||||
storage_path: new_storage_path,
|
||||
path_string: new_path_string,
|
||||
parent_id,
|
||||
drive_id: self.drive_id,
|
||||
created_at: self.created_at,
|
||||
@@ -562,12 +541,9 @@ impl Folder {
|
||||
pub fn get_absolute_path<P: AsRef<std::path::Path>>(&self, root_path: P) -> std::path::PathBuf {
|
||||
let mut result = std::path::PathBuf::from(root_path.as_ref());
|
||||
|
||||
// Skip leading '/' from path_string to avoid creating absolute path incorrectly
|
||||
let relative_path = if self.path_string.starts_with('/') {
|
||||
&self.path_string[1..]
|
||||
} else {
|
||||
&self.path_string
|
||||
};
|
||||
// Skip leading '/' to avoid creating an absolute path incorrectly
|
||||
let path_string = self.storage_path.as_str();
|
||||
let relative_path = path_string.strip_prefix('/').unwrap_or(path_string);
|
||||
|
||||
if !relative_path.is_empty() {
|
||||
result.push(relative_path);
|
||||
|
||||
@@ -8,6 +8,17 @@ pub enum TrashedItemType {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// Owned decomposition of a [`TrashedItem`] (see
|
||||
/// [`TrashedItem::into_parts`]).
|
||||
pub struct TrashedItemParts {
|
||||
pub id: Uuid,
|
||||
pub original_id: Uuid,
|
||||
pub item_type: TrashedItemType,
|
||||
pub name: String,
|
||||
pub original_path: String,
|
||||
pub trashed_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
pub struct TrashedItem {
|
||||
id: Uuid,
|
||||
original_id: Uuid,
|
||||
@@ -98,6 +109,20 @@ impl TrashedItem {
|
||||
self.deletion_date
|
||||
}
|
||||
|
||||
/// Decompose into owned parts for DTO conversion — moves `name` /
|
||||
/// `original_path` instead of the getter clones `to_dto` used to make
|
||||
/// per trash row (benches/ROUND11.md; the File/Folder/Contact pattern).
|
||||
pub fn into_parts(self) -> TrashedItemParts {
|
||||
TrashedItemParts {
|
||||
id: self.id,
|
||||
original_id: self.original_id,
|
||||
item_type: self.item_type,
|
||||
name: self.name,
|
||||
original_path: self.original_path,
|
||||
trashed_at: self.trashed_at,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn days_until_deletion(&self) -> i64 {
|
||||
let now = Utc::now();
|
||||
(self.deletion_date - now).num_days().max(0)
|
||||
|
||||
Reference in New Issue
Block a user