Flush OMEMO store only after encrypting for all recipients.

Instead of flushing the OMEMO store to disk after each operation, do it
only once after all recipients are processed.

A user reported a long delay between hitting enter on the keyboard and the
message being sent on the wire in an OMEMO-enabled group chat. This patch
hopefully improves this situation.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2026-03-12 12:00:22 +01:00
parent ff65db0b10
commit cbe6dac448

View File

@@ -612,9 +612,13 @@ omemo_sessions_keyfile(void)
return omemo_ctx.sessions.keyfile; return omemo_ctx.sessions.keyfile;
} }
static gboolean omemo_sessions_keyfile_save_disable = FALSE;
void void
omemo_sessions_keyfile_save(void) omemo_sessions_keyfile_save(void)
{ {
if (omemo_sessions_keyfile_save_disable)
return;
save_keyfile(&omemo_ctx.sessions); save_keyfile(&omemo_ctx.sessions);
} }
@@ -766,6 +770,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
unsigned char* key_tag = NULL; unsigned char* key_tag = NULL;
size_t ciphertext_len, tag_len; size_t ciphertext_len, tag_len;
omemo_sessions_keyfile_save_disable = TRUE;
ciphertext_len = strlen(message); ciphertext_len = strlen(message);
ciphertext = malloc(ciphertext_len); ciphertext = malloc(ciphertext_len);
if (!ciphertext) { if (!ciphertext) {
@@ -983,6 +989,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
} }
out: out:
omemo_sessions_keyfile_save_disable = FALSE;
omemo_sessions_keyfile_save();
g_list_free_full(keys, (GDestroyNotify)omemo_key_free); g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
free(ciphertext); free(ciphertext);
gcry_free(key); gcry_free(key);