mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
Avoid deadlock when processing deletes and edits concurrently
This commit is contained in:
@@ -8758,8 +8758,9 @@ function saveEditedMessages(
|
|||||||
alreadyInTransaction: true,
|
alreadyInTransaction: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const { conversationId, messageId, readStatus, sentAt } of history) {
|
try {
|
||||||
const [query, params] = sql`
|
for (const { conversationId, messageId, readStatus, sentAt } of history) {
|
||||||
|
const [query, params] = sql`
|
||||||
INSERT INTO edited_messages (
|
INSERT INTO edited_messages (
|
||||||
conversationId,
|
conversationId,
|
||||||
messageId,
|
messageId,
|
||||||
@@ -8773,7 +8774,29 @@ function saveEditedMessages(
|
|||||||
);
|
);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
db.prepare(query).run(params);
|
db.prepare(query).run(params);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
const [messageExistsQuery, messageExistsParams] = sql`
|
||||||
|
SELECT EXISTS(
|
||||||
|
SELECT 1 FROM messages
|
||||||
|
WHERE messages.id = ${mainMessage.id}
|
||||||
|
);
|
||||||
|
`;
|
||||||
|
const messageExists = db
|
||||||
|
.prepare(messageExistsQuery, {
|
||||||
|
pluck: true,
|
||||||
|
})
|
||||||
|
.get<number>(messageExistsParams);
|
||||||
|
|
||||||
|
if (messageExists !== 1) {
|
||||||
|
logger.warn(
|
||||||
|
'saveEditedMessages: save failed because message does not exist'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Some other, unknown error
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -365,8 +365,8 @@ export async function modifyTargetMessage(
|
|||||||
if (!isFirstRun && !skipEdits) {
|
if (!isFirstRun && !skipEdits) {
|
||||||
const edits = Edits.forMessage(message.attributes);
|
const edits = Edits.forMessage(message.attributes);
|
||||||
log.info(`${logId}: ${edits.length} edits in second run`);
|
log.info(`${logId}: ${edits.length} edits in second run`);
|
||||||
await Promise.all(
|
edits.map(editAttributes =>
|
||||||
edits.map(editAttributes =>
|
drop(
|
||||||
conversation.queueJob('modifyTargetMessage/edits', () =>
|
conversation.queueJob('modifyTargetMessage/edits', () =>
|
||||||
handleEditMessage(message.attributes, editAttributes)
|
handleEditMessage(message.attributes, editAttributes)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user