From 625a11dd5ccfab767509c40e7bd0280dbf81e32e Mon Sep 17 00:00:00 2001 From: iequidoo Date: Fri, 13 Mar 2026 10:41:19 -0300 Subject: [PATCH] feat: Add timestamp, id to msgs_index7 and speed up "normal chatlist" (#7848) --- src/chatlist.rs | 10 +++++++--- src/sql/migrations.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/chatlist.rs b/src/chatlist.rs index 534dccf91..56618d301 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -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? }; diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 576b148d4..a1905e9ef 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -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?