Deduplicate incoming attachments on disk

This commit is contained in:
trevor-signal
2026-02-05 14:48:31 -05:00
committed by GitHub
parent 85cc412b40
commit 834f0c7775
51 changed files with 1727 additions and 560 deletions

View File

@@ -48,7 +48,7 @@ import { sleep } from '../ts/util/sleep.std.js';
import { toWebStream } from '../ts/util/toWebStream.node.js';
import { createLogger } from '../ts/logging/log.std.js';
import {
deleteAll as deleteAllAttachments,
deleteAllAttachments,
deleteAllBadges,
deleteAllDownloads,
deleteAllDraftAttachments,
@@ -62,7 +62,7 @@ import {
getAvatarsPath,
getDownloadsPath,
getDraftPath,
getPath,
getAttachmentsPath,
getStickersPath,
getTempPath,
} from './attachments.node.js';
@@ -450,6 +450,14 @@ function deleteOrphanedAttachments({
await sql.sqlRead('finishGetKnownMessageAttachments', cursor);
}
}
const protectedAttachments = await sql.sqlRead(
'getAllProtectedAttachmentPaths'
);
for (const protectedAttachment of protectedAttachments) {
orphanedAttachments.delete(protectedAttachment);
}
log.info(
`cleanupOrphanedAttachments: ${totalAttachmentsFound} attachments and \
${totalDownloadsFound} downloads found on disk`
@@ -514,7 +522,7 @@ export function initialize({
}
initialized = true;
attachmentsDir = getPath(configDir);
attachmentsDir = getAttachmentsPath(configDir);
stickersDir = getStickersPath(configDir);
tempDir = getTempPath(configDir);
draftDir = getDraftPath(configDir);