Skip to content

Commit 3e8b050

Browse files
committed
2squash: Optimize SQL statement and add db migration for hidden InFresh messages
1 parent 40f11d3 commit 3e8b050

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/chat.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,21 +3324,19 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
33243324
AND chat_id=?",
33253325
(MessageState::InNoticed, MessageState::InFresh, chat_id),
33263326
)?;
3327+
// This is mainly for reactions. We don't select `InNoticed` messages because they are
3328+
// normally a result of `mark_old_messages_as_noticed()` which happens on all devices
3329+
// anyway.
33273330
let mut stmt = conn.prepare(
33283331
"SELECT id FROM msgs
3329-
WHERE state>=? AND state<?
3330-
AND hidden=1
3331-
AND chat_id=?
3332+
WHERE state=? AND hidden=1 AND chat_id=?
33323333
ORDER BY id DESC LIMIT 100",
33333334
)?;
33343335
let hidden_msgs = stmt
3335-
.query_map(
3336-
(MessageState::InFresh, MessageState::InSeen, chat_id),
3337-
|row| {
3338-
let id: MsgId = row.get(0)?;
3339-
Ok(id)
3340-
},
3341-
)?
3336+
.query_map((MessageState::InFresh, chat_id), |row| {
3337+
let id: MsgId = row.get(0)?;
3338+
Ok(id)
3339+
})?
33423340
.collect::<std::result::Result<Vec<_>, _>>()?;
33433341
Ok((nr_msgs_noticed, hidden_msgs))
33443342
};

src/sql/migrations.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,19 @@ CREATE INDEX msgs_status_updates_index2 ON msgs_status_updates (uid);
10701070
.await?;
10711071
}
10721072

1073+
inc_and_check(&mut migration_version, 124)?;
1074+
if dbversion < migration_version {
1075+
// As now incoming reactions are added as hidden `InFresh` messages, just in case make
1076+
// existing hidden `InFresh` ones `InNoticed`. Currently we don't create such messages other
1077+
// than reactions, and even they are only becoming such now, but we can't inspect all
1078+
// previous core versions.
1079+
sql.execute_migration(
1080+
"UPDATE msgs SET state=13 WHERE state=10 AND hidden=1",
1081+
migration_version,
1082+
)
1083+
.await?;
1084+
}
1085+
10731086
let new_version = sql
10741087
.get_raw_config_int(VERSION_CFG)
10751088
.await?

0 commit comments

Comments
 (0)