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:
link2xt
2023-02-24 10:11:13 +00:00
parent bc9e347a80
commit e9668b3cfa

View File

@@ -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.