mirror of
https://github.com/chatmail/core.git
synced 2026-05-13 03:46:32 +03:00
perf: make FullChat::from_dc_chat_id concurrent
However, hand-testing get_full_chat_by_id` did not show a significant performance increase for a dummy group with 100 contacts.
This commit is contained in:
@@ -62,33 +62,33 @@ impl FullChat {
|
|||||||
let rust_chat_id = ChatId::new(chat_id);
|
let rust_chat_id = ChatId::new(chat_id);
|
||||||
let chat = Chat::load_from_db(context, rust_chat_id).await?;
|
let chat = Chat::load_from_db(context, rust_chat_id).await?;
|
||||||
|
|
||||||
let contact_ids = get_chat_contacts(context, rust_chat_id).await?;
|
let (
|
||||||
let past_contact_ids = get_past_chat_contacts(context, rust_chat_id).await?;
|
contact_ids,
|
||||||
|
past_contact_ids,
|
||||||
let mut contacts = Vec::with_capacity(contact_ids.len());
|
profile_image,
|
||||||
|
color,
|
||||||
for contact_id in &contact_ids {
|
fresh_message_counter,
|
||||||
contacts.push(
|
ephemeral_timer,
|
||||||
ContactObject::try_from_dc_contact(
|
can_send,
|
||||||
context,
|
) = futures::try_join!(
|
||||||
Contact::get_by_id(context, *contact_id)
|
get_chat_contacts(context, rust_chat_id),
|
||||||
.await
|
get_past_chat_contacts(context, rust_chat_id),
|
||||||
.context("failed to load contact")?,
|
chat.get_profile_image(context),
|
||||||
)
|
chat.get_color(context),
|
||||||
.await?,
|
rust_chat_id.get_fresh_msg_cnt(context),
|
||||||
|
rust_chat_id.get_ephemeral_timer(context),
|
||||||
|
chat.can_send(context),
|
||||||
|
)?;
|
||||||
|
let contacts = futures::future::try_join_all(contact_ids.iter().map(|contact_id| async {
|
||||||
|
ContactObject::try_from_dc_contact(
|
||||||
|
context,
|
||||||
|
Contact::get_by_id(context, *contact_id)
|
||||||
|
.await
|
||||||
|
.context("failed to load contact")?,
|
||||||
)
|
)
|
||||||
}
|
.await
|
||||||
|
}))
|
||||||
let profile_image = match chat.get_profile_image(context).await? {
|
.await?;
|
||||||
Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()),
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let color = color_int_to_hex_string(chat.get_color(context).await?);
|
|
||||||
let fresh_message_counter = rust_chat_id.get_fresh_msg_cnt(context).await?;
|
|
||||||
let ephemeral_timer = rust_chat_id.get_ephemeral_timer(context).await?.to_u32();
|
|
||||||
|
|
||||||
let can_send = chat.can_send(context).await?;
|
|
||||||
|
|
||||||
let was_seen_recently = if chat.get_type() == Chattype::Single {
|
let was_seen_recently = if chat.get_type() == Chattype::Single {
|
||||||
match contact_ids.first() {
|
match contact_ids.first() {
|
||||||
@@ -108,7 +108,11 @@ impl FullChat {
|
|||||||
id: chat_id,
|
id: chat_id,
|
||||||
name: chat.name.clone(),
|
name: chat.name.clone(),
|
||||||
is_protected: chat.is_protected(),
|
is_protected: chat.is_protected(),
|
||||||
profile_image, //BLOBS ?
|
//BLOBS ?
|
||||||
|
profile_image: match profile_image {
|
||||||
|
Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
||||||
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
|
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
|
||||||
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
||||||
@@ -117,14 +121,14 @@ impl FullChat {
|
|||||||
contacts,
|
contacts,
|
||||||
contact_ids: contact_ids.iter().map(|id| id.to_u32()).collect(),
|
contact_ids: contact_ids.iter().map(|id| id.to_u32()).collect(),
|
||||||
past_contact_ids: past_contact_ids.iter().map(|id| id.to_u32()).collect(),
|
past_contact_ids: past_contact_ids.iter().map(|id| id.to_u32()).collect(),
|
||||||
color,
|
color: color_int_to_hex_string(color),
|
||||||
fresh_message_counter,
|
fresh_message_counter,
|
||||||
is_contact_request: chat.is_contact_request(),
|
is_contact_request: chat.is_contact_request(),
|
||||||
is_protection_broken: chat.is_protection_broken(),
|
is_protection_broken: chat.is_protection_broken(),
|
||||||
is_device_chat: chat.is_device_talk(),
|
is_device_chat: chat.is_device_talk(),
|
||||||
self_in_group: contact_ids.contains(&ContactId::SELF),
|
self_in_group: contact_ids.contains(&ContactId::SELF),
|
||||||
is_muted: chat.is_muted(),
|
is_muted: chat.is_muted(),
|
||||||
ephemeral_timer,
|
ephemeral_timer: ephemeral_timer.to_u32(),
|
||||||
can_send,
|
can_send,
|
||||||
was_seen_recently,
|
was_seen_recently,
|
||||||
mailing_list_address,
|
mailing_list_address,
|
||||||
|
|||||||
Reference in New Issue
Block a user