mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Cache INSERT statement in receive_imf
It reduces iteration time by ~8% in message reception benchmarks ran by `cargo criterion --bench receive_emails`.
This commit is contained in:
@@ -1149,7 +1149,10 @@ async fn add_parts(
|
||||
// also change `MsgId::trash()` and `delete_expired_messages()`
|
||||
let trash = chat_id.is_trash() || (is_location_kml && msg.is_empty());
|
||||
|
||||
let row_id = context.sql.insert(
|
||||
let row_id = context
|
||||
.sql
|
||||
.call(|conn| {
|
||||
let mut stmt = conn.prepare_cached(
|
||||
r#"
|
||||
INSERT INTO msgs
|
||||
(
|
||||
@@ -1179,8 +1182,8 @@ SET rfc724_mid=excluded.rfc724_mid, chat_id=excluded.chat_id,
|
||||
bytes=excluded.bytes, mime_headers=excluded.mime_headers, mime_in_reply_to=excluded.mime_in_reply_to,
|
||||
mime_references=excluded.mime_references, mime_modified=excluded.mime_modified, error=excluded.error, ephemeral_timer=excluded.ephemeral_timer,
|
||||
ephemeral_timestamp=excluded.ephemeral_timestamp, download_state=excluded.download_state, hop_info=excluded.hop_info
|
||||
"#,
|
||||
paramsv![
|
||||
"#)?;
|
||||
stmt.execute(params![
|
||||
replace_msg_id,
|
||||
rfc724_mid,
|
||||
if trash { DC_CHAT_ID_TRASH } else { chat_id },
|
||||
@@ -1219,7 +1222,11 @@ SET rfc724_mid=excluded.rfc724_mid, chat_id=excluded.chat_id,
|
||||
DownloadState::Done
|
||||
},
|
||||
mime_parser.hop_info
|
||||
]).await?;
|
||||
])?;
|
||||
let row_id = conn.last_insert_rowid();
|
||||
Ok(row_id)
|
||||
})
|
||||
.await?;
|
||||
|
||||
// We only replace placeholder with a first part,
|
||||
// afterwards insert additional parts.
|
||||
|
||||
Reference in New Issue
Block a user