Skip to content

Commit

Permalink
2squash: Optimize SQL statement and add db migration for hidden InFre…
Browse files Browse the repository at this point in the history
…sh messages
  • Loading branch information
iequidoo committed Nov 26, 2024
1 parent 40f11d3 commit 3e8b050
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3324,21 +3324,19 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
AND chat_id=?",
(MessageState::InNoticed, MessageState::InFresh, chat_id),
)?;
// This is mainly for reactions. We don't select `InNoticed` messages because they are
// normally a result of `mark_old_messages_as_noticed()` which happens on all devices
// anyway.
let mut stmt = conn.prepare(
"SELECT id FROM msgs
WHERE state>=? AND state<?
AND hidden=1
AND chat_id=?
WHERE state=? AND hidden=1 AND chat_id=?
ORDER BY id DESC LIMIT 100",
)?;
let hidden_msgs = stmt
.query_map(
(MessageState::InFresh, MessageState::InSeen, chat_id),
|row| {
let id: MsgId = row.get(0)?;
Ok(id)
},
)?
.query_map((MessageState::InFresh, chat_id), |row| {
let id: MsgId = row.get(0)?;
Ok(id)
})?
.collect::<std::result::Result<Vec<_>, _>>()?;
Ok((nr_msgs_noticed, hidden_msgs))
};
Expand Down
13 changes: 13 additions & 0 deletions src/sql/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,19 @@ CREATE INDEX msgs_status_updates_index2 ON msgs_status_updates (uid);
.await?;
}

inc_and_check(&mut migration_version, 124)?;
if dbversion < migration_version {
// As now incoming reactions are added as hidden `InFresh` messages, just in case make
// existing hidden `InFresh` ones `InNoticed`. Currently we don't create such messages other
// than reactions, and even they are only becoming such now, but we can't inspect all
// previous core versions.
sql.execute_migration(
"UPDATE msgs SET state=13 WHERE state=10 AND hidden=1",
migration_version,
)
.await?;
}

let new_version = sql
.get_raw_config_int(VERSION_CFG)
.await?
Expand Down

0 comments on commit 3e8b050

Please sign in to comment.