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
@@ -128,8 +128,8 @@ fn reject_path_traversal(path: &str) -> Result<(), AppError> {
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"))
}