mirror of
https://github.com/chatmail/core.git
synced 2026-10-26 14:57:59 +03:00
refactor: create all keyupdates in a single transaction
This commit is contained in:
+19
-10
@@ -188,16 +188,25 @@ pub(crate) async fn maybe_send_keyupdate_message(context: &Context) -> Result<()
|
||||
}
|
||||
|
||||
let recipients = keyupdate_recipients(context, KEYUPDATE_MAX_RECIPIENTS).await?;
|
||||
for chunk in recipients.chunks(KEYUPDATE_CHUNK_CONTACTS) {
|
||||
let envelope = envelope_recipients(chunk);
|
||||
let rfc724_mid = create_outgoing_rfc724_mid();
|
||||
let keys = chunk.iter().map(|r| r.public_key.clone()).collect();
|
||||
let queued_msg = keyupdate_message(context, &rfc724_mid, keys, envelope).await?;
|
||||
context
|
||||
.sql
|
||||
.transaction(|tx| insert_into_smtp(tx, &rfc724_mid, &queued_msg))
|
||||
.await?;
|
||||
}
|
||||
info!(
|
||||
context,
|
||||
"Sending keyupdate messages to {} recipients.",
|
||||
recipients.len()
|
||||
);
|
||||
let is_bot = context.get_config_bool(Config::Bot).await?;
|
||||
context
|
||||
.sql
|
||||
.transaction(|tx| {
|
||||
for chunk in recipients.chunks(KEYUPDATE_CHUNK_CONTACTS) {
|
||||
let envelope = envelope_recipients(chunk);
|
||||
let rfc724_mid = create_outgoing_rfc724_mid();
|
||||
let keys = chunk.iter().map(|r| r.public_key.clone()).collect();
|
||||
let queued_msg = keyupdate_message(is_bot, &rfc724_mid, keys, envelope);
|
||||
insert_into_smtp(tx, &rfc724_mid, &queued_msg)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Record only after queueing, so failed queueing is retried by a later check.
|
||||
context
|
||||
|
||||
+5
-12
@@ -2381,24 +2381,18 @@ fn keyupdate_body() -> MimePart<'static> {
|
||||
|
||||
/// Returns a keyupdate message informing the owners of `recipient_keys`
|
||||
/// about the current key and relay list, see [`crate::keyupdate`].
|
||||
pub(crate) async fn keyupdate_message(
|
||||
context: &Context,
|
||||
pub(crate) fn keyupdate_message(
|
||||
is_bot: bool,
|
||||
rfc724_mid: &str,
|
||||
recipient_keys: Vec<SignedPublicKey>,
|
||||
recipients: Vec<String>,
|
||||
) -> Result<QueuedMail> {
|
||||
info!(
|
||||
context,
|
||||
"Sending keyupdate message to {} recipients.",
|
||||
recipient_keys.len()
|
||||
);
|
||||
) -> QueuedMail {
|
||||
let message = keyupdate_body();
|
||||
|
||||
let is_bot = context.get_config_bool(Config::Bot).await?;
|
||||
let headers = non_chat_headers(is_bot, "Keyupdate");
|
||||
let message = add_headers_to_encrypted_part(message, headers);
|
||||
|
||||
let queued_mail = QueuedMail {
|
||||
QueuedMail {
|
||||
raw_message: part_to_bytes(message),
|
||||
display_name: String::new(),
|
||||
rfc724_mid: rfc724_mid.to_string(),
|
||||
@@ -2418,8 +2412,7 @@ pub(crate) async fn keyupdate_message(
|
||||
recipients,
|
||||
sent_to: Vec::new(),
|
||||
bcc_self: false,
|
||||
};
|
||||
Ok(queued_mail)
|
||||
}
|
||||
}
|
||||
|
||||
/// Renders MIME part into a vector of bytes.
|
||||
|
||||
Reference in New Issue
Block a user