From c0878a79286a31350535b7f3903db532ed56fb10 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Sun, 2 Aug 2026 12:34:42 +0200 Subject: [PATCH] fix(storage-usage): keep trashed files in usage till they a permenently deleted --- src/application/services/storage_usage_service.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/application/services/storage_usage_service.rs b/src/application/services/storage_usage_service.rs index ac607a88..2ce7cf0c 100644 --- a/src/application/services/storage_usage_service.rs +++ b/src/application/services/storage_usage_service.rs @@ -752,6 +752,12 @@ impl StorageUsagePort for StorageUsageService { /// FROM` guard to skip no-op rewrites so idle drives don't churn /// dead tuples. Runs from the same reconciliation ticker as the /// user sweep; failure is logged but doesn't stop the next tick. + /// + /// Trashed files ARE included in the sum — matching the hot-path + /// delta which never decrements on `move_to_trash`. Trash weight + /// stays billed to the drive/user until permanent deletion (that's + /// when the delta subtracts). Excluding trash here would make + /// `used_bytes` oscillate between sweep runs and delta writes. async fn update_all_drives_storage_usage(&self) -> Result { debug!("Starting drive storage-usage reconciliation sweep"); let result = sqlx::query( @@ -762,7 +768,6 @@ impl StorageUsagePort for StorageUsageService { LEFT JOIN ( SELECT drive_id, SUM(size)::bigint AS total FROM storage.files - WHERE NOT is_trashed GROUP BY drive_id ) t ON t.drive_id = d2.id WHERE d.id = d2.id