cargo fmt
This commit is contained in:
@@ -168,8 +168,7 @@ impl<'a> Repository<'a> {
|
||||
let mut participant_cache: HashMap<String, i32> = HashMap::new();
|
||||
|
||||
// Prepare collections for the batch inserts.
|
||||
let mut db_messages: Vec<MessageRecord> =
|
||||
Vec::with_capacity(in_messages.len());
|
||||
let mut db_messages: Vec<MessageRecord> = Vec::with_capacity(in_messages.len());
|
||||
let mut conv_msg_records: Vec<InsertableConversationMessage> =
|
||||
Vec::with_capacity(in_messages.len());
|
||||
|
||||
@@ -178,7 +177,8 @@ impl<'a> Repository<'a> {
|
||||
let sender_id = match &message.sender {
|
||||
Participant::Me => None,
|
||||
Participant::Remote { display_name, .. } => {
|
||||
if let Some(cached_participant_id) = participant_cache.get(display_name) {
|
||||
if let Some(cached_participant_id) = participant_cache.get(display_name)
|
||||
{
|
||||
Some(*cached_participant_id)
|
||||
} else {
|
||||
// Try to load from DB first
|
||||
@@ -239,19 +239,22 @@ impl<'a> Repository<'a> {
|
||||
// processed instead of re-querying the DB.
|
||||
if let Some(last_msg) = db_messages.last() {
|
||||
use crate::schema::conversations::dsl as conv_dsl;
|
||||
diesel::update(conv_dsl::conversations.filter(conv_dsl::id.eq(conversation_guid)))
|
||||
.set((
|
||||
conv_dsl::date.eq(last_msg.date),
|
||||
conv_dsl::last_message_preview.eq::<Option<String>>(Some(last_msg.text.clone())),
|
||||
))
|
||||
.execute(conn)?;
|
||||
diesel::update(
|
||||
conv_dsl::conversations.filter(conv_dsl::id.eq(conversation_guid)),
|
||||
)
|
||||
.set((
|
||||
conv_dsl::date.eq(last_msg.date),
|
||||
conv_dsl::last_message_preview
|
||||
.eq::<Option<String>>(Some(last_msg.text.clone())),
|
||||
))
|
||||
.execute(conn)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// TODO: May need to update conversation metadata here, but this has a perf impact.
|
||||
// Ideally we would consolidate this in the code above, assuming we're only inserting *new* messages, but
|
||||
// Ideally we would consolidate this in the code above, assuming we're only inserting *new* messages, but
|
||||
// this may not necessarily be the case.
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user