first iteration of faster sorting

This commit is contained in:
holger krekel
2022-03-31 10:32:32 +02:00
parent 4880f9ff32
commit c6d901d799
2 changed files with 16 additions and 9 deletions

View File

@@ -13,6 +13,7 @@
- start ephemeral timer when seen status is synchronized via IMAP #3122
- do not delete duplicate messages on IMAP immediately to accidentally deleting
the last copy #3138
- speed up loading of chat messages #3171
### Changes
- add more SMTP logging #3093

View File

@@ -2241,26 +2241,34 @@ pub async fn get_chat_msgs(
};
Ok((
row.get::<_, MsgId>("id")?,
row.get::<_, i64>("timestamp")?,
row.get::<_, MsgId>("id")?,
!is_info_msg,
))
}
} else {
|row: &rusqlite::Row| {
Ok((
row.get::<_, MsgId>("id")?,
row.get::<_, i64>("timestamp")?,
row.get::<_, MsgId>("id")?,
false,
))
}
};
let process_rows = |rows: rusqlite::MappedRows<_>| {
// It is faster to sort here rather than
// let sqlite execute an ORDER BY clause.
let mut sorted_rows = Vec::new();
for row in rows {
let (ts, curr_id, exclude_message): (i64, MsgId, bool) = row?;
sorted_rows.push((ts, curr_id, exclude_message));
}
sorted_rows.sort_unstable();
let mut ret = Vec::new();
let mut last_day = 0;
let cnv_to_local = dc_gm2local_offset();
for row in rows {
let (curr_id, ts, exclude_message): (MsgId, i64, bool) = row?;
for (ts, curr_id, exclude_message) in sorted_rows {
if let Some(marker_id) = marker1before {
if curr_id == marker_id {
ret.push(ChatItem::Marker1);
@@ -2296,8 +2304,7 @@ pub async fn get_chat_msgs(
m.param GLOB \"*S=*\"
OR m.from_id == ?
OR m.to_id == ?
)
ORDER BY m.timestamp, m.id;",
);",
paramsv![chat_id, DC_CONTACT_ID_INFO, DC_CONTACT_ID_INFO],
process_row,
process_rows,
@@ -2307,11 +2314,10 @@ pub async fn get_chat_msgs(
context
.sql
.query_map(
"SELECT m.id AS id, m.timestamp AS timestamp
"SELECT m.id as id, m.timestamp as timestamp
FROM msgs m
WHERE m.chat_id=?
AND m.hidden=0
ORDER BY m.timestamp, m.id;",
AND m.hidden=0;",
paramsv![chat_id],
process_row,
process_rows,