perf: Add timestamp to msgs_index7 and speed up Chatlist::try_load() (#7848)

This speeds up chatlisting by 3--4 times on my biggest profile, so the difference is visually
noticeable, particularly after dropping disk caches. Before, `msgs_index2` was used which has less
ordering and requires a full scan of `msgs` table.
This commit is contained in:
iequidoo
2026-03-13 10:41:19 -03:00
committed by iequidoo
parent 1a24bf612a
commit 0560c13ae5
2 changed files with 56 additions and 53 deletions

View File

@@ -2477,6 +2477,16 @@ UPDATE msgs SET state=24 WHERE state=18; -- Change OutPreparing to OutFailed.
.await?;
}
inc_and_check(&mut migration_version, 156)?;
if dbversion < migration_version {
sql.execute_migration(
"DROP INDEX IF EXISTS msgs_index7;
CREATE INDEX msgs_index7 ON msgs (state, hidden, chat_id, timestamp);",
migration_version,
)
.await?;
}
let new_version = sql
.get_raw_config_int(VERSION_CFG)
.await?