perf: round 10 — auth alloc purge, parent-herd batching, query-shape pack, NC 304s
Benchmark-gated (benches/ROUND10.md; every change carries a BEFORE/AFTER harness with equivalence/safety gates — two designs were rejected or rewritten by their own benches before adoption): - Auth hot path: TokenClaims/CurrentUser display fields to Arc<str>, role to inline SmolStr end-to-end (Bearer, cookie, Basic-auth cache) — 4→1 allocs per authenticated request, 3→0 per warm DAV request; JWT Encoding/Decoding/Validation built once. - Cold shared-album herd: leader-inline parent batching in PgAclEngine (+ cascade try_get_with single-flight) — 100→2 parent queries per 100-thumb cold herd, herd wall 1.9x, sequential + warm paths unchanged, all ROUND8/9 safety gates plus new herd-equivalence gates. - Query-shape pack: share download double-fetch 2→1 (2.18x), contact-group COUNT(*) 14.9x, save_faces UNNEST 3.9x, playlist reorder UNNEST 63.7x (now atomic), search files∥folders join! 1.45x, move drive-lookup join! 2.14x, trash partial (drive_id, trashed_at) indexes, CalDAV event-gate narrow read, favorites/recents binary-decode port, dead count_files removed. - NC surface: preview + avatar honour If-None-Match (e2e: 5 KB and 197 KB → 0 bytes per revalidation), avatar WebP→PNG transcode memoised, PROPFIND/trashbin integer+date emits on stack formatters, folder-header enrichment join!, chunk-PUT retry stat folded into create_new open. - common::fmt integer rendering rewritten on the std 2-digit LUT after the round's own bench caught the div-loop losing to to_string (16.1 ns vs 22.5; speeds every prior-round call site). - Micro-pack: WebDAV scope probe borrow-only, ShareService base_url snapshot, cookie_secure OnceLock, Arc'd AES-GCM cipher, stack request-id, tantivy analyzer clone dropped. - SPA: search stale-guard + AbortController (10→1 completed round-trips, stale-clobber gone), getFolder in-flight dedup, gridColumns matchMedia hoist (10k→0 style reads). Backend: cargo fmt + clippy -D warnings clean, 524 tests green. Frontend: npm run check clean, 301 vitest green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018DdM7V7M3QPW7HEHg3gLov
This commit is contained in:
@@ -79,6 +79,11 @@ const MAX_CONCURRENT_HASHES: usize = 2;
|
||||
|
||||
pub struct ShareService {
|
||||
config: Arc<AppConfig>,
|
||||
/// `AppConfig::base_url()` snapshot, taken once at construction —
|
||||
/// the method re-reads `OXICLOUD_BASE_URL` from the environment (a
|
||||
/// global env-lock + String build) and was being called per DTO row
|
||||
/// in the share listings. Process-invariant, so snapshot it.
|
||||
base_url: String,
|
||||
share_repository: Arc<SharePgRepository>,
|
||||
file_repository: Arc<FileBlobReadRepository>,
|
||||
folder_repository: Arc<FolderDbRepository>,
|
||||
@@ -107,6 +112,7 @@ impl ShareService {
|
||||
authorization: Arc<PgAclEngine>,
|
||||
) -> Self {
|
||||
Self {
|
||||
base_url: config.base_url(),
|
||||
config,
|
||||
share_repository,
|
||||
file_repository,
|
||||
@@ -204,7 +210,7 @@ impl ShareService {
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&share, &self.base_url))
|
||||
}
|
||||
|
||||
pub fn issue_unlock_jwt(&self, share_token: &str) -> Result<String, DomainError> {
|
||||
@@ -338,7 +344,7 @@ impl ShareUseCase for ShareService {
|
||||
|
||||
// Return DTO with the requested expires_at (grant subquery on the share
|
||||
// row would return NULL at this point since INSERT ran before the grant).
|
||||
let mut response = ShareDto::from_entity(&saved_share, &self.config.base_url());
|
||||
let mut response = ShareDto::from_entity(&saved_share, &self.base_url);
|
||||
response.expires_at = dto.expires_at;
|
||||
Ok(response)
|
||||
}
|
||||
@@ -354,7 +360,7 @@ impl ShareUseCase for ShareService {
|
||||
}
|
||||
|
||||
// Convert the entity to DTO for the response
|
||||
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&share, &self.base_url))
|
||||
}
|
||||
|
||||
async fn get_shared_link_by_token(&self, token: &str) -> Result<ShareDto, DomainError> {
|
||||
@@ -380,7 +386,7 @@ impl ShareUseCase for ShareService {
|
||||
// Convert the entities to DTOs for the response
|
||||
let share_dtos = active_shares
|
||||
.iter()
|
||||
.map(|s| ShareDto::from_entity(s, &self.config.base_url()))
|
||||
.map(|s| ShareDto::from_entity(s, &self.base_url))
|
||||
.collect();
|
||||
|
||||
Ok(share_dtos)
|
||||
@@ -427,7 +433,7 @@ impl ShareUseCase for ShareService {
|
||||
|
||||
// Use the requested expires_at for the response (subquery in update_share
|
||||
// runs before set_expiry_for_subject committed, so entity may lag).
|
||||
let mut response = ShareDto::from_entity(&updated_share, &self.config.base_url());
|
||||
let mut response = ShareDto::from_entity(&updated_share, &self.base_url);
|
||||
if dto.expires_at.is_some() {
|
||||
response.expires_at = dto.expires_at;
|
||||
}
|
||||
@@ -462,7 +468,7 @@ impl ShareUseCase for ShareService {
|
||||
// Convert the entities to DTOs
|
||||
let share_dtos: Vec<ShareDto> = shares
|
||||
.iter()
|
||||
.map(|s| ShareDto::from_entity(s, &self.config.base_url()))
|
||||
.map(|s| ShareDto::from_entity(s, &self.base_url))
|
||||
.collect();
|
||||
|
||||
// Create the paginated result
|
||||
@@ -506,7 +512,7 @@ impl ShareUseCase for ShareService {
|
||||
}
|
||||
|
||||
// Password verified (or not required) — return full share metadata
|
||||
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&share, &self.base_url))
|
||||
}
|
||||
|
||||
async fn register_shared_link_access(&self, token: &str) -> Result<(), DomainError> {
|
||||
@@ -540,7 +546,9 @@ mod tests {
|
||||
|
||||
/// Test-only service that mirrors `ShareService` logic but accepts generic repos.
|
||||
struct ShareServiceForTest<SR, FR, FoR, PH> {
|
||||
#[allow(dead_code)]
|
||||
config: Arc<AppConfig>,
|
||||
base_url: String,
|
||||
share_repository: Arc<SR>,
|
||||
file_repository: Arc<FR>,
|
||||
folder_repository: Arc<FoR>,
|
||||
@@ -563,6 +571,7 @@ mod tests {
|
||||
password_hasher: Arc<PH>,
|
||||
) -> Self {
|
||||
Self {
|
||||
base_url: config.base_url(),
|
||||
config,
|
||||
share_repository,
|
||||
file_repository,
|
||||
@@ -641,7 +650,7 @@ mod tests {
|
||||
.save_share(&share)
|
||||
.await
|
||||
.map_err(|e| ShareServiceError::Repository(e.to_string()))?;
|
||||
Ok(ShareDto::from_entity(&saved_share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&saved_share, &self.base_url))
|
||||
}
|
||||
|
||||
async fn get_shared_link(
|
||||
@@ -659,7 +668,7 @@ mod tests {
|
||||
if share.is_expired() {
|
||||
return Err(ShareServiceError::Expired.into());
|
||||
}
|
||||
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&share, &self.base_url))
|
||||
}
|
||||
|
||||
async fn get_shared_link_by_token(&self, token: &str) -> Result<ShareDto, DomainError> {
|
||||
@@ -673,7 +682,7 @@ mod tests {
|
||||
if share.is_expired() {
|
||||
return Err(ShareServiceError::Expired.into());
|
||||
}
|
||||
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&share, &self.base_url))
|
||||
}
|
||||
|
||||
async fn get_shared_links_for_item(
|
||||
@@ -690,7 +699,7 @@ mod tests {
|
||||
Ok(shares
|
||||
.into_iter()
|
||||
.filter(|s| !s.is_expired())
|
||||
.map(|s| ShareDto::from_entity(&s, &self.config.base_url()))
|
||||
.map(|s| ShareDto::from_entity(&s, &self.base_url))
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -720,7 +729,7 @@ mod tests {
|
||||
.update_share(&share)
|
||||
.await
|
||||
.map_err(|e| ShareServiceError::Repository(e.to_string()))?;
|
||||
Ok(ShareDto::from_entity(&updated, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&updated, &self.base_url))
|
||||
}
|
||||
|
||||
async fn delete_shared_link(
|
||||
@@ -749,7 +758,7 @@ mod tests {
|
||||
.map_err(|e| ShareServiceError::Repository(e.to_string()))?;
|
||||
let dtos = shares
|
||||
.iter()
|
||||
.map(|s| ShareDto::from_entity(s, &self.config.base_url()))
|
||||
.map(|s| ShareDto::from_entity(s, &self.base_url))
|
||||
.collect();
|
||||
Ok(PaginatedResponseDto::new(dtos, page, per_page, total))
|
||||
}
|
||||
@@ -779,9 +788,9 @@ mod tests {
|
||||
"Invalid share password",
|
||||
));
|
||||
}
|
||||
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
|
||||
Ok(ShareDto::from_entity(&share, &self.base_url))
|
||||
}
|
||||
None => Ok(ShareDto::from_entity(&share, &self.config.base_url())),
|
||||
None => Ok(ShareDto::from_entity(&share, &self.base_url)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,15 +924,6 @@ mod tests {
|
||||
Ok((Vec::new(), 0))
|
||||
}
|
||||
|
||||
async fn count_files(
|
||||
&self,
|
||||
_folder_id: Option<&str>,
|
||||
_criteria: &crate::application::dtos::search_dto::SearchCriteriaDto,
|
||||
_user_id: Uuid,
|
||||
) -> Result<usize, DomainError> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
async fn stream_files_in_subtree(
|
||||
&self,
|
||||
_folder_id: &str,
|
||||
|
||||
Reference in New Issue
Block a user