mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-24 18:38:15 +01:00
Keep messages in their own transaction in saveMessagesIndividually
This commit is contained in:
@@ -2731,7 +2731,6 @@ function saveMessage(
|
||||
_testOnlyAvoidNormalizingAttachments?: boolean;
|
||||
}
|
||||
): string {
|
||||
// NB: `saveMessagesIndividually` relies on `saveMessage` being atomic
|
||||
const { alreadyInTransaction, forceSave, jobToInsert, ourAci } = options;
|
||||
if (!alreadyInTransaction) {
|
||||
return db.transaction(() => {
|
||||
@@ -2901,6 +2900,10 @@ function saveMessage(
|
||||
} satisfies Omit<MessageTypeUnhydrated, 'json'>;
|
||||
|
||||
if (id && !forceSave) {
|
||||
if (normalizeAttachmentData) {
|
||||
saveMessageAttachments(db, message);
|
||||
}
|
||||
|
||||
const result = db
|
||||
.prepare(
|
||||
// UPDATE queries that set the value of a primary key column can be very slow when
|
||||
@@ -2919,16 +2922,12 @@ function saveMessage(
|
||||
return id;
|
||||
}
|
||||
|
||||
strictAssert(result.changes === 1, 'One row should have been changed');
|
||||
|
||||
if (normalizeAttachmentData) {
|
||||
saveMessageAttachments(db, message);
|
||||
}
|
||||
|
||||
if (jobToInsert) {
|
||||
insertJob(db, jobToInsert);
|
||||
}
|
||||
|
||||
strictAssert(result.changes === 1, 'One row should have been changed');
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -2991,10 +2990,7 @@ function saveMessagesIndividually(
|
||||
const failedIndices: Array<number> = [];
|
||||
arrayOfMessages.forEach((message, index) => {
|
||||
try {
|
||||
saveMessage(db, message, {
|
||||
...options,
|
||||
alreadyInTransaction: true,
|
||||
});
|
||||
saveMessage(db, message, options);
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
'saveMessagesIndividually: failed to save message',
|
||||
|
||||
Reference in New Issue
Block a user