mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-25 02:48:23 +01:00
Update message attachment migration
This commit is contained in:
@@ -129,10 +129,9 @@ export type MessageType = MessageAttributesType;
|
||||
// - Make sure the name matches the one in `MessageAttributeTypes`
|
||||
// - Update `hydrateMessage`
|
||||
//
|
||||
export const MESSAGE_COLUMNS = [
|
||||
const MESSAGE_PRIMARY_KEY_COLUMNS = ['id'] as const;
|
||||
export const MESSAGE_NON_PRIMARY_KEY_COLUMNS = [
|
||||
'json',
|
||||
|
||||
'id',
|
||||
'body',
|
||||
'conversationId',
|
||||
'expirationStartTimestamp',
|
||||
@@ -161,6 +160,11 @@ export const MESSAGE_COLUMNS = [
|
||||
'unidentifiedDeliveryReceived',
|
||||
] as const;
|
||||
|
||||
export const MESSAGE_COLUMNS = [
|
||||
...MESSAGE_PRIMARY_KEY_COLUMNS,
|
||||
...MESSAGE_NON_PRIMARY_KEY_COLUMNS,
|
||||
] as const;
|
||||
|
||||
export type MessageTypeUnhydrated = {
|
||||
json: string;
|
||||
|
||||
|
||||
@@ -191,6 +191,7 @@ import {
|
||||
AttachmentDownloadSource,
|
||||
MESSAGE_COLUMNS,
|
||||
MESSAGE_ATTACHMENT_COLUMNS,
|
||||
MESSAGE_NON_PRIMARY_KEY_COLUMNS,
|
||||
} from './Interface';
|
||||
import {
|
||||
_removeAllCallLinks,
|
||||
@@ -235,6 +236,7 @@ import {
|
||||
import { generateMessageId } from '../util/generateMessageId';
|
||||
import type { ConversationColorType, CustomColorType } from '../types/Colors';
|
||||
import { sqlLogger } from './sqlLogger';
|
||||
import { APPLICATION_OCTET_STREAM } from '../types/MIME';
|
||||
|
||||
type ConversationRow = Readonly<{
|
||||
json: string;
|
||||
@@ -2559,8 +2561,8 @@ function saveMessageAttachment({
|
||||
conversationId,
|
||||
sentAt,
|
||||
clientUuid: attachment.clientUuid,
|
||||
size: attachment.size,
|
||||
contentType: attachment.contentType,
|
||||
size: attachment.size ?? 0,
|
||||
contentType: attachment.contentType ?? APPLICATION_OCTET_STREAM,
|
||||
path: attachment.path,
|
||||
localKey: attachment.localKey,
|
||||
plaintextHash: attachment.plaintextHash,
|
||||
@@ -2642,8 +2644,7 @@ function saveMessageAttachment({
|
||||
INSERT OR REPLACE INTO message_attachments
|
||||
(${MESSAGE_ATTACHMENT_COLUMNS.join(', ')})
|
||||
VALUES
|
||||
(${MESSAGE_ATTACHMENT_COLUMNS.map(name => `$${name}`).join(', ')})
|
||||
RETURNING rowId;
|
||||
(${MESSAGE_ATTACHMENT_COLUMNS.map(name => `$${name}`).join(', ')});
|
||||
`
|
||||
).run(values);
|
||||
}
|
||||
@@ -2830,20 +2831,24 @@ function saveMessage(
|
||||
|
||||
if (id && !forceSave) {
|
||||
db.prepare(
|
||||
// UPDATE queries that set the value of a primary key column can be very slow when
|
||||
// that key is referenced via a foreign key constraint, so we are careful to exclude
|
||||
// it here.
|
||||
`
|
||||
UPDATE messages SET
|
||||
${MESSAGE_COLUMNS.map(name => `${name} = $${name}`).join(', ')}
|
||||
WHERE id = $id;
|
||||
UPDATE messages SET
|
||||
${MESSAGE_NON_PRIMARY_KEY_COLUMNS.map(name => `${name} = $${name}`).join(', ')}
|
||||
WHERE id = $id;
|
||||
`
|
||||
).run({ ...payloadWithoutJson, json: objectToJSON(dataToSaveAsJSON) });
|
||||
|
||||
if (normalizeAttachmentData) {
|
||||
saveMessageAttachments(db, message);
|
||||
}
|
||||
|
||||
if (jobToInsert) {
|
||||
insertJob(db, jobToInsert);
|
||||
}
|
||||
|
||||
if (normalizeAttachmentData) {
|
||||
saveMessageAttachments(db, message);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,24 +85,32 @@ export function updateToSchemaVersion1360(
|
||||
) STRICT;
|
||||
`);
|
||||
|
||||
db.exec(
|
||||
'CREATE INDEX message_attachments_messageId ON message_attachments (messageId);'
|
||||
);
|
||||
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_all_thumbnailPath ON message_attachments (thumbnailPath);'
|
||||
);
|
||||
db.exec(
|
||||
'CREATE INDEX message_attachments_all_screenshotPath ON message_attachments (screenshotPath);'
|
||||
);
|
||||
db.exec(
|
||||
'CREATE INDEX message_attachments_all_backupThumbnailPath ON message_attachments (backupThumbnailPath);'
|
||||
);
|
||||
// The following indexes were removed in migration 1370
|
||||
|
||||
// db.exec(
|
||||
// 'CREATE INDEX message_attachments_messageId
|
||||
// ON message_attachments (messageId);'
|
||||
// );
|
||||
// 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_all_thumbnailPath
|
||||
// ON message_attachments (thumbnailPath);'
|
||||
// );
|
||||
// db.exec(
|
||||
// 'CREATE INDEX message_attachments_all_screenshotPath
|
||||
// ON message_attachments (screenshotPath);'
|
||||
// );
|
||||
// db.exec(
|
||||
// 'CREATE INDEX message_attachments_all_backupThumbnailPath
|
||||
// ON message_attachments (backupThumbnailPath);'
|
||||
// );
|
||||
|
||||
db.pragma('user_version = 1360');
|
||||
})();
|
||||
|
||||
31
ts/sql/migrations/1370-message-attachment-indexes.ts
Normal file
31
ts/sql/migrations/1370-message-attachment-indexes.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import type { WritableDB } from '../Interface';
|
||||
|
||||
export const version = 1370;
|
||||
|
||||
export function updateToSchemaVersion1370(
|
||||
currentVersion: number,
|
||||
db: WritableDB,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1370) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
DROP INDEX IF EXISTS message_attachments_messageId;
|
||||
DROP INDEX IF EXISTS message_attachments_plaintextHash;
|
||||
DROP INDEX IF EXISTS message_attachments_path;
|
||||
DROP INDEX IF EXISTS message_attachments_all_thumbnailPath;
|
||||
DROP INDEX IF EXISTS message_attachments_all_screenshotPath;
|
||||
DROP INDEX IF EXISTS message_attachments_all_backupThumbnailPath;
|
||||
`);
|
||||
db.pragma('user_version = 1370');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion1370: success!');
|
||||
}
|
||||
@@ -111,10 +111,11 @@ import { updateToSchemaVersion1320 } from './1320-unprocessed-received-at-date';
|
||||
import { updateToSchemaVersion1330 } from './1330-sync-tasks-type-index';
|
||||
import { updateToSchemaVersion1340 } from './1340-recent-gifs';
|
||||
import { updateToSchemaVersion1350 } from './1350-notification-profiles';
|
||||
import { updateToSchemaVersion1360 } from './1360-attachments';
|
||||
import {
|
||||
updateToSchemaVersion1360,
|
||||
updateToSchemaVersion1370,
|
||||
version as MAX_VERSION,
|
||||
} from './1360-attachments';
|
||||
} from './1370-message-attachment-indexes';
|
||||
|
||||
import { DataWriter } from '../Server';
|
||||
|
||||
@@ -2104,6 +2105,7 @@ export const SCHEMA_VERSIONS = [
|
||||
updateToSchemaVersion1340,
|
||||
updateToSchemaVersion1350,
|
||||
updateToSchemaVersion1360,
|
||||
updateToSchemaVersion1370,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
||||
Reference in New Issue
Block a user