From 6e26d1c694446997a4c34a09fb5457ad7aabe301 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Jun 2026 08:10:54 +0000 Subject: [PATCH] refactor: remove dead OptimizedFileContent::Mmap variant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OptimizedFileContent::Mmap was constructed nowhere — the documented "Tier 2: memory-mapped I/O (10-100 MB)" path was never wired, so optimized_inner only ever returns Bytes (<10 MB) or Stream (>=10 MB). The variant survived only as an enum case plus two dead match arms in the file and share download handlers. Remove the variant and its arms, and fix the now-misleading retrieval-service tier docs (everything >=10 MB streams via CDC chunk reassembly with the backend read-ahead; there is no mmap tier). Behaviour is unchanged — the deleted arms were unreachable. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01JG5yYZ9s868mJwqT2Qz7ez --- src/application/ports/file_ports.rs | 6 ++---- .../services/file_retrieval_service.rs | 4 ++-- src/interfaces/api/handlers/file_handler.rs | 14 -------------- src/interfaces/api/handlers/share_handler.rs | 15 --------------- 4 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/application/ports/file_ports.rs b/src/application/ports/file_ports.rs index fa68438c..9f607241 100644 --- a/src/application/ports/file_ports.rs +++ b/src/application/ports/file_ports.rs @@ -93,7 +93,7 @@ pub trait FileUploadUseCase: Send + Sync + 'static { /// Optimized file content returned by the retrieval service. /// /// The handler only needs to map each variant to the appropriate HTTP -/// response; all caching / transcoding / mmap decisions happen in the +/// response; all caching / transcoding decisions happen in the /// application layer. pub enum OptimizedFileContent { /// Small-file content (possibly transcoded / compressed) already in RAM. @@ -102,9 +102,7 @@ pub enum OptimizedFileContent { mime_type: Arc, was_transcoded: bool, }, - /// Memory-mapped file (10–100 MB). - Mmap(Bytes), - /// Streaming download for very large files (≥100 MB). + /// Streaming download for everything above the in-RAM cache threshold. Stream(Pin> + Send>>), } diff --git a/src/application/services/file_retrieval_service.rs b/src/application/services/file_retrieval_service.rs index 00a6741b..490a423e 100644 --- a/src/application/services/file_retrieval_service.rs +++ b/src/application/services/file_retrieval_service.rs @@ -26,8 +26,8 @@ const CACHE_THRESHOLD: u64 = 10 * 1024 * 1024; /// Implements a multi-tier download strategy: /// - Tier 0: Write-behind cache (just-uploaded files still in RAM) /// - Tier 1: Hot cache + optional WebP transcoding (<10 MB) -/// - Tier 2: Memory-mapped I/O (10–100 MB) -/// - Tier 3: Streaming (≥100 MB) +/// - Tier 2: Streaming for everything ≥10 MB — CDC chunk reassembly with the +/// backend's read-ahead (`read_prefetch`); no whole-file buffering. pub struct FileRetrievalService { file_read: Arc, content_cache: Option>, diff --git a/src/interfaces/api/handlers/file_handler.rs b/src/interfaces/api/handlers/file_handler.rs index f27e6124..00e6312d 100644 --- a/src/interfaces/api/handlers/file_handler.rs +++ b/src/interfaces/api/handlers/file_handler.rs @@ -750,20 +750,6 @@ impl FileHandler { data, mime_type, .. } => Self::build_cached_response(data, &mime_type, &disposition, &etag) .into_response(), - OptimizedFileContent::Mmap(mmap_data) => Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, &*file_dto.mime_type) - .header(header::CONTENT_DISPOSITION, &disposition) - .header(header::CONTENT_LENGTH, mmap_data.len()) - .header(header::ETAG, &etag) - .header( - header::CACHE_CONTROL, - "private, max-age=3600, must-revalidate", - ) - .header(header::ACCEPT_RANGES, "bytes") - .body(Body::from(mmap_data)) - .unwrap() - .into_response(), OptimizedFileContent::Stream(pinned_stream) => Response::builder() .status(StatusCode::OK) .header(header::CONTENT_TYPE, &*file_dto.mime_type) diff --git a/src/interfaces/api/handlers/share_handler.rs b/src/interfaces/api/handlers/share_handler.rs index b19bd9ee..2bda63b9 100644 --- a/src/interfaces/api/handlers/share_handler.rs +++ b/src/interfaces/api/handlers/share_handler.rs @@ -501,21 +501,6 @@ async fn serve_share_file( .body(Body::from(data)) .unwrap() .into_response(), - OptimizedFileContent::Mmap(mmap_data) => Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, &*mime) - .header(header::CONTENT_DISPOSITION, &disposition) - .header(header::CONTENT_LENGTH, mmap_data.len()) - .header(header::ACCEPT_RANGES, "bytes") - .header(header::ETAG, &etag) - .header( - header::CACHE_CONTROL, - "private, max-age=3600, must-revalidate", - ) - .header(header::VARY, "Cookie, Range") - .body(Body::from(mmap_data)) - .unwrap() - .into_response(), OptimizedFileContent::Stream(stream) => Response::builder() .status(StatusCode::OK) .header(header::CONTENT_TYPE, &*mime)