feat: Add timestamp, id to msgs_index7 and speed up "normal chatlist" (#7848)

This commit is contained in:
iequidoo
2026-03-13 10:41:19 -03:00
parent 4d537544ef
commit 625a11dd5c
2 changed files with 18 additions and 3 deletions

View File

@@ -272,15 +272,19 @@ impl Chatlist {
AND m.id=(
SELECT id
FROM msgs
WHERE chat_id=c.id
AND (hidden=0 OR state=?)
-- state=`OutDraft`.
WHERE state=19 AND hidden=1 AND chat_id=c.id
-- `InFresh`...`OutDelivered` inclusive except `OutDraft`.
OR state IN (10,13,16,18,20,24,26)
AND hidden=0
AND chat_id=c.id
ORDER BY timestamp DESC, id DESC LIMIT 1)
WHERE c.id>9 AND c.id!=?
AND (c.blocked=0 OR c.blocked=2)
AND NOT c.archived=?
GROUP BY c.id
ORDER BY c.id=0 DESC, c.archived=? DESC, IFNULL(NULLIF(m.timestamp,0),c.created_timestamp) DESC, m.id DESC;",
(MessageState::OutDraft, skip_id, ChatVisibility::Archived, ChatVisibility::Pinned),
(skip_id, ChatVisibility::Archived, ChatVisibility::Pinned),
process_row,
).await?
};

View File

@@ -2373,6 +2373,17 @@ ALTER TABLE contacts ADD COLUMN name_normalized TEXT;
.await?;
}
inc_and_check(&mut migration_version, 152)?;
if dbversion < migration_version {
sql.execute_migration(
"UPDATE msgs SET state=26 WHERE state=28;
DROP INDEX IF EXISTS msgs_index7;
CREATE INDEX msgs_index7 ON msgs (state, hidden, chat_id, timestamp, id);",
migration_version,
)
.await?;
}
let new_version = sql
.get_raw_config_int(VERSION_CFG)
.await?