fix: use explicit counter for danglingFilesOnDisk in referencedFiles calc

Matches the orphanedFiles counting pattern and avoids a subtle
discrepancy if two dangling records shared the same filename.
This commit is contained in:
Jannis Braun
2026-03-23 01:53:25 +01:00
parent b40999995b
commit d687988ba8
+3 -2
View File
@@ -189,6 +189,7 @@ export function getStorageStats(): StorageStats {
let referencedSize = 0;
let orphanedFiles = 0;
let orphanedSize = 0;
let danglingFilesOnDisk = 0;
const breakdownMap = new Map<string, { count: number; size: number }>();
for (const file of diskFiles) {
@@ -201,7 +202,7 @@ export function getStorageStats(): StorageStats {
if (danglingFilenames.has(file.filename)) {
// File is on disk but its attachment record points to a deleted message
// — counted as dangling, not referenced
danglingFilesOnDisk++;
} else if (referenced.has(file.filename)) {
referencedSize += file.size;
} else {
@@ -224,7 +225,7 @@ export function getStorageStats(): StorageStats {
return {
totalFiles: diskFiles.length,
totalSize,
referencedFiles: diskFiles.length - orphanedFiles - danglingFilenames.size,
referencedFiles: diskFiles.length - orphanedFiles - danglingFilesOnDisk,
referencedSize,
orphanedFiles,
orphanedSize,