perf: replace recursive spawn-per-folder search with O(1) ltree queries

- Add search_files_in_subtree() to FileReadPort with ltree-based SQL
- Add list_descendant_folders() to FolderRepository with ltree GiST index
- Implement both in PG repositories (single query per entity type)
- Remove search_parallel() fan-out (O(N) tokio::spawn → 0 spawns)
- Remove passes_file_filter/passes_folder_filter (filtering now in SQL)
- Fix SearchCriteriaDto cache key: JSON serialization → u64 hash (15x faster)
- Fix escaped quote literals in webdav_handler.rs handle_put function
This commit is contained in:
Diocrafts
2026-02-23 00:17:40 +01:00
parent 92e0364a60
commit b501c4052b
7 changed files with 379 additions and 277 deletions
+19
View File
@@ -103,6 +103,25 @@ pub trait FileReadPort: Send + Sync + 'static {
user_id: &str,
) -> Result<(Vec<File>, usize), DomainError>;
/// Search files recursively in a folder subtree using ltree.
///
/// When `root_folder_id` is Some, uses ltree descendant queries to find
/// all files within the subtree rooted at that folder. When None, searches
/// all files for the user. This replaces the O(N) recursive spawn-per-folder
/// approach with O(1) SQL queries.
///
/// Returns a tuple of (matching files, total count for pagination).
async fn search_files_in_subtree(
&self,
root_folder_id: Option<&str>,
criteria: &SearchCriteriaDto,
user_id: &str,
) -> Result<(Vec<File>, usize), DomainError> {
// Default: delegate to paginated search (non-recursive fallback)
self.search_files_paginated(root_folder_id, criteria, user_id)
.await
}
/// Count files matching the search criteria (without loading them).
///
/// Used for pagination metadata without fetching the actual files.