perf: OnceLock for env var, Arc<CurrentUser> in auth, pre-compute query lowercase

- rate_limit: cache OXICLOUD_TRUST_PROXY_HEADERS in OnceLock<bool> to avoid
  syscall on every request (~500ns → ~1ns)
- auth middleware: insert Arc<CurrentUser> instead of bare CurrentUser;
  all 5 extractors now clone Arc (~1ns) instead of 4 Strings (~60-100ns)
- search_service: pre-compute query.to_lowercase() once before loops,
  eliminating N redundant heap allocations per search
This commit is contained in:
Diocrafts
2026-03-07 11:23:56 +01:00
parent e4bcab0488
commit 9f08460027
8 changed files with 796 additions and 42 deletions
@@ -95,8 +95,8 @@ const PROPFIND_BATCH_SIZE: i64 = 500;
/// user-scoped `PathResolverService` methods.
fn extract_user(req: &Request<Body>) -> Result<CurrentUser, AppError> {
req.extensions()
.get::<CurrentUser>()
.cloned()
.get::<Arc<CurrentUser>>()
.map(|arc| (**arc).clone())
.ok_or_else(|| AppError::unauthorized("Authentication required"))
}
@@ -209,7 +209,7 @@ async fn handle_webdav_dispatch(
// prefix when the path doesn't already include it.
// Extract user_id before any async call to keep the future Send.
let path = if !path.is_empty() && method.as_str() != "OPTIONS" {
let user_id = req.extensions().get::<CurrentUser>().map(|u| u.id.clone());
let user_id = req.extensions().get::<Arc<CurrentUser>>().map(|u| u.id.clone());
if let Some(uid) = user_id {
resolve_webdav_path(&state, &uid, &path)
.await