Update message attachment migration
This commit is contained in:
parent
a034045935
commit
115b79e4ac
8 changed files with 97 additions and 90 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue