upgradeSchema: New keepOnDisk option, used for edits

This commit is contained in:
Scott Nonnenberg 2024-01-08 16:31:24 -08:00
parent 661727c290
commit d1aa47544b
4 changed files with 27 additions and 17 deletions

View file

@ -111,7 +111,7 @@ type MigrationsModuleType = {
}>; }>;
upgradeMessageSchema: ( upgradeMessageSchema: (
attributes: MessageAttributesType, attributes: MessageAttributesType,
options?: { maxVersion?: number } options?: { maxVersion?: number; keepOnDisk?: boolean }
) => Promise<MessageAttributesType>; ) => Promise<MessageAttributesType>;
writeMessageAttachments: ( writeMessageAttachments: (
message: MessageAttributesType message: MessageAttributesType
@ -266,24 +266,26 @@ export function initializeMigrations({
}), }),
upgradeMessageSchema: ( upgradeMessageSchema: (
message: MessageAttributesType, message: MessageAttributesType,
options: { maxVersion?: number } = {} options: { maxVersion?: number; keepOnDisk?: boolean } = {}
) => { ) => {
const { maxVersion } = options; const { maxVersion, keepOnDisk } = options;
return MessageType.upgradeSchema(message, { return MessageType.upgradeSchema(message, {
writeNewAttachmentData, deleteOnDisk,
getRegionCode,
getAbsoluteAttachmentPath, getAbsoluteAttachmentPath,
makeObjectUrl, getAbsoluteStickerPath,
revokeObjectUrl,
getImageDimensions, getImageDimensions,
getRegionCode,
makeImageThumbnail, makeImageThumbnail,
makeObjectUrl,
makeVideoScreenshot, makeVideoScreenshot,
revokeObjectUrl,
writeNewAttachmentData,
writeNewStickerData,
keepOnDisk,
logger, logger,
maxVersion, maxVersion,
getAbsoluteStickerPath,
writeNewStickerData,
deleteOnDisk,
}); });
}, },
writeMessageAttachments: MessageType.createAttachmentDataWriter({ writeMessageAttachments: MessageType.createAttachmentDataWriter({

View file

@ -52,6 +52,7 @@ export type ContextType = {
height: number; height: number;
}>; }>;
getRegionCode: () => string | undefined; getRegionCode: () => string | undefined;
keepOnDisk?: boolean;
logger: LoggerType; logger: LoggerType;
makeImageThumbnail: (params: { makeImageThumbnail: (params: {
size: number; size: number;
@ -380,14 +381,19 @@ const toVersion1 = _withSchemaVersion({
context, context,
options options
): Promise<AttachmentType> => { ): Promise<AttachmentType> => {
const { deleteOnDisk } = context; const { deleteOnDisk, keepOnDisk } = context;
const rotatedAttachment = await autoOrientJPEG( const rotatedAttachment = await autoOrientJPEG(
attachment, attachment,
context, context,
options options
); );
if (attachment.path) { if (
!keepOnDisk &&
attachment !== rotatedAttachment &&
rotatedAttachment.data &&
attachment.path
) {
await deleteOnDisk(attachment.path); await deleteOnDisk(attachment.path);
} }
@ -500,6 +506,7 @@ export const upgradeSchema = async (
makeVideoScreenshot, makeVideoScreenshot,
writeNewStickerData, writeNewStickerData,
deleteOnDisk, deleteOnDisk,
keepOnDisk,
logger, logger,
maxVersion = CURRENT_SCHEMA_VERSION, maxVersion = CURRENT_SCHEMA_VERSION,
}: ContextType }: ContextType
@ -559,6 +566,7 @@ export const upgradeSchema = async (
getImageDimensions, getImageDimensions,
makeImageThumbnail, makeImageThumbnail,
makeVideoScreenshot, makeVideoScreenshot,
keepOnDisk,
logger, logger,
getAbsoluteStickerPath, getAbsoluteStickerPath,
getRegionCode, getRegionCode,
@ -640,7 +648,7 @@ export const processNewAttachment = async (
logger, logger,
}); });
if (attachment.path) { if (rotatedAttachment !== attachment && attachment.path) {
await deleteOnDisk(attachment.path); await deleteOnDisk(attachment.path);
} }
} }

View file

@ -2,7 +2,6 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import type { MessageModel } from '../models/messages'; import type { MessageModel } from '../models/messages';
import * as log from '../logging/log';
import { getEnvironment, Environment } from '../environment'; import { getEnvironment, Environment } from '../environment';
export function getMessageModelLogger(model: MessageModel): MessageModel { export function getMessageModelLogger(model: MessageModel): MessageModel {
@ -37,8 +36,6 @@ export function getMessageModelLogger(model: MessageModel): MessageModel {
// Disallowed set of methods & attributes // Disallowed set of methods & attributes
log.warn(`MessageModelLogger: model.${property}`, new Error().stack);
if (typeof target[property] === 'function') { if (typeof target[property] === 'function') {
return target[property].bind(target); return target[property].bind(target);
} }

View file

@ -134,7 +134,10 @@ export async function handleEditMessage(
} }
const upgradedEditedMessageData = const upgradedEditedMessageData =
await window.Signal.Migrations.upgradeMessageSchema(editAttributes.message); await window.Signal.Migrations.upgradeMessageSchema(
editAttributes.message,
{ keepOnDisk: true }
);
// Copies over the attachments from the main message if they're the same // Copies over the attachments from the main message if they're the same
// and they have already been downloaded. // and they have already been downloaded.