Skip to content

Commit d13eb2f

Browse files
committed
feat: receive_imf::add_parts(): Get rid of extra Chat::load_from_db() calls
1 parent 5476f69 commit d13eb2f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/receive_imf.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,12 +1673,12 @@ async fn add_parts(
16731673
}
16741674
}
16751675

1676+
let mut chat = Chat::load_from_db(context, chat_id).await?;
1677+
16761678
if mime_parser.incoming && !chat_id.is_trash() {
16771679
// It can happen that the message is put into a chat
16781680
// but the From-address is not a member of this chat.
16791681
if !chat::is_contact_in_chat(context, chat_id, from_id).await? {
1680-
let chat = Chat::load_from_db(context, chat_id).await?;
1681-
16821682
// Mark the sender as overridden.
16831683
// The UI will prepend `~` to the sender's name,
16841684
// indicating that the sender is not part of the group.
@@ -1699,7 +1699,6 @@ async fn add_parts(
16991699
let is_location_kml = mime_parser.location_kml.is_some();
17001700
let is_mdn = !mime_parser.mdn_reports.is_empty();
17011701

1702-
let mut chat = Chat::load_from_db(context, chat_id).await?;
17031702
let mut group_changes = match chat.typ {
17041703
_ if chat.id.is_special() => GroupChangesInfo::default(),
17051704
Chattype::Single => GroupChangesInfo::default(),
@@ -1864,10 +1863,7 @@ async fn add_parts(
18641863
None
18651864
};
18661865

1867-
// if a chat is protected and the message is fully downloaded, check additional properties
18681866
if !chat_id.is_special() && is_partial_download.is_none() {
1869-
let chat = Chat::load_from_db(context, chat_id).await?;
1870-
18711867
// For outgoing emails in the 1:1 chat we have an exception that
18721868
// they are allowed to be unencrypted:
18731869
// 1. They can't be an attack (they are outgoing, not incoming)
@@ -1884,6 +1880,7 @@ async fn add_parts(
18841880
}
18851881
}
18861882
}
1883+
drop(chat); // Avoid using stale `chat` object.
18871884

18881885
let sort_timestamp = tweak_sort_timestamp(
18891886
context,

0 commit comments

Comments
 (0)