mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-17 23:34:14 +01:00
Deduplicate incoming attachments on disk
This commit is contained in:
53
ts/sql/migrations/1650-protected-attachments.std.ts
Normal file
53
ts/sql/migrations/1650-protected-attachments.std.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2026 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import type { WritableDB } from '../Interface.std.js';
|
||||
|
||||
export default function updateToSchemaVersion1650(db: WritableDB): void {
|
||||
db.exec(`
|
||||
CREATE TABLE attachments_protected_from_deletion (
|
||||
path TEXT NOT NULL,
|
||||
UNIQUE (path)
|
||||
) STRICT;
|
||||
`);
|
||||
|
||||
db.exec(`
|
||||
CREATE INDEX message_attachments_plaintextHash ON message_attachments (plaintextHash);
|
||||
`);
|
||||
db.exec(`
|
||||
CREATE INDEX message_attachments_path ON message_attachments (path);
|
||||
`);
|
||||
db.exec(`
|
||||
CREATE INDEX message_attachments_thumbnailPath ON message_attachments (thumbnailPath);
|
||||
`);
|
||||
db.exec(`
|
||||
CREATE INDEX message_attachments_screenshotPath ON message_attachments (screenshotPath);
|
||||
`);
|
||||
db.exec(`
|
||||
CREATE INDEX message_attachments_backupThumbnailPath ON message_attachments (backupThumbnailPath);
|
||||
`);
|
||||
|
||||
db.exec(`
|
||||
CREATE TRIGGER stop_protecting_attachments_after_update
|
||||
AFTER UPDATE OF path, thumbnailPath, screenshotPath, backupThumbnailPath
|
||||
ON message_attachments
|
||||
WHEN
|
||||
OLD.path IS NOT NEW.path OR
|
||||
OLD.thumbnailPath IS NOT NEW.thumbnailPath OR
|
||||
OLD.screenshotPath IS NOT NEW.screenshotPath OR
|
||||
OLD.backupThumbnailPath IS NOT NEW.backupThumbnailPath
|
||||
BEGIN
|
||||
DELETE FROM attachments_protected_from_deletion
|
||||
WHERE path IN (NEW.path, NEW.thumbnailPath, NEW.screenshotPath, NEW.backupThumbnailPath);
|
||||
END;
|
||||
`);
|
||||
|
||||
db.exec(`
|
||||
CREATE TRIGGER stop_protecting_attachments_after_insert
|
||||
AFTER INSERT
|
||||
ON message_attachments
|
||||
BEGIN
|
||||
DELETE FROM attachments_protected_from_deletion
|
||||
WHERE path IN (NEW.path, NEW.thumbnailPath, NEW.screenshotPath, NEW.backupThumbnailPath);
|
||||
END;
|
||||
`);
|
||||
}
|
||||
@@ -141,6 +141,7 @@ import updateToSchemaVersion1610 from './1610-has-contacts.std.js';
|
||||
import updateToSchemaVersion1620 from './1620-sort-bigger-media.std.js';
|
||||
import updateToSchemaVersion1630 from './1630-message-pin-message-data.std.js';
|
||||
import updateToSchemaVersion1640 from './1640-key-transparency.std.js';
|
||||
import updateToSchemaVersion1650 from './1650-protected-attachments.std.js';
|
||||
|
||||
import { DataWriter } from '../Server.node.js';
|
||||
|
||||
@@ -1642,6 +1643,7 @@ export const SCHEMA_VERSIONS: ReadonlyArray<SchemaUpdateType> = [
|
||||
{ version: 1620, update: updateToSchemaVersion1620 },
|
||||
{ version: 1630, update: updateToSchemaVersion1630 },
|
||||
{ version: 1640, update: updateToSchemaVersion1640 },
|
||||
{ version: 1650, update: updateToSchemaVersion1650 },
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
||||
Reference in New Issue
Block a user