mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
first iteration of faster sorting
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
- start ephemeral timer when seen status is synchronized via IMAP #3122
|
- start ephemeral timer when seen status is synchronized via IMAP #3122
|
||||||
- do not delete duplicate messages on IMAP immediately to accidentally deleting
|
- do not delete duplicate messages on IMAP immediately to accidentally deleting
|
||||||
the last copy #3138
|
the last copy #3138
|
||||||
|
- speed up loading of chat messages #3171
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- add more SMTP logging #3093
|
- add more SMTP logging #3093
|
||||||
|
|||||||
24
src/chat.rs
24
src/chat.rs
@@ -2241,26 +2241,34 @@ pub async fn get_chat_msgs(
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
row.get::<_, MsgId>("id")?,
|
|
||||||
row.get::<_, i64>("timestamp")?,
|
row.get::<_, i64>("timestamp")?,
|
||||||
|
row.get::<_, MsgId>("id")?,
|
||||||
!is_info_msg,
|
!is_info_msg,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|row: &rusqlite::Row| {
|
|row: &rusqlite::Row| {
|
||||||
Ok((
|
Ok((
|
||||||
row.get::<_, MsgId>("id")?,
|
|
||||||
row.get::<_, i64>("timestamp")?,
|
row.get::<_, i64>("timestamp")?,
|
||||||
|
row.get::<_, MsgId>("id")?,
|
||||||
false,
|
false,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let process_rows = |rows: rusqlite::MappedRows<_>| {
|
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 ret = Vec::new();
|
||||||
let mut last_day = 0;
|
let mut last_day = 0;
|
||||||
let cnv_to_local = dc_gm2local_offset();
|
let cnv_to_local = dc_gm2local_offset();
|
||||||
for row in rows {
|
for (ts, curr_id, exclude_message) in sorted_rows {
|
||||||
let (curr_id, ts, exclude_message): (MsgId, i64, bool) = row?;
|
|
||||||
if let Some(marker_id) = marker1before {
|
if let Some(marker_id) = marker1before {
|
||||||
if curr_id == marker_id {
|
if curr_id == marker_id {
|
||||||
ret.push(ChatItem::Marker1);
|
ret.push(ChatItem::Marker1);
|
||||||
@@ -2296,8 +2304,7 @@ pub async fn get_chat_msgs(
|
|||||||
m.param GLOB \"*S=*\"
|
m.param GLOB \"*S=*\"
|
||||||
OR m.from_id == ?
|
OR m.from_id == ?
|
||||||
OR m.to_id == ?
|
OR m.to_id == ?
|
||||||
)
|
);",
|
||||||
ORDER BY m.timestamp, m.id;",
|
|
||||||
paramsv![chat_id, DC_CONTACT_ID_INFO, DC_CONTACT_ID_INFO],
|
paramsv![chat_id, DC_CONTACT_ID_INFO, DC_CONTACT_ID_INFO],
|
||||||
process_row,
|
process_row,
|
||||||
process_rows,
|
process_rows,
|
||||||
@@ -2307,11 +2314,10 @@ pub async fn get_chat_msgs(
|
|||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.query_map(
|
.query_map(
|
||||||
"SELECT m.id AS id, m.timestamp AS timestamp
|
"SELECT m.id as id, m.timestamp as timestamp
|
||||||
FROM msgs m
|
FROM msgs m
|
||||||
WHERE m.chat_id=?
|
WHERE m.chat_id=?
|
||||||
AND m.hidden=0
|
AND m.hidden=0;",
|
||||||
ORDER BY m.timestamp, m.id;",
|
|
||||||
paramsv![chat_id],
|
paramsv![chat_id],
|
||||||
process_row,
|
process_row,
|
||||||
process_rows,
|
process_rows,
|
||||||
|
|||||||
Reference in New Issue
Block a user