mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 18:36:30 +03:00
use combined index (state, hidden, chat_id) to speed up marknoticed_chat()
This commit is contained in:
14
src/chat.rs
14
src/chat.rs
@@ -1745,11 +1745,12 @@ pub async fn get_chat_msgs(
|
||||
}
|
||||
|
||||
pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(), Error> {
|
||||
// "WHERE" below uses the index `(state, hidden, chat_id)`, see get_fresh_msg_cnt() for reasoning
|
||||
if !context
|
||||
.sql
|
||||
.exists(
|
||||
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
|
||||
paramsv![chat_id, MessageState::InFresh],
|
||||
"SELECT id FROM msgs WHERE state=? AND hidden=0 AND chat_id=?;",
|
||||
paramsv![MessageState::InFresh, chat_id],
|
||||
)
|
||||
.await?
|
||||
{
|
||||
@@ -1760,10 +1761,11 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(),
|
||||
.sql
|
||||
.execute(
|
||||
"UPDATE msgs
|
||||
SET state=13
|
||||
WHERE chat_id=?
|
||||
AND state=10;",
|
||||
paramsv![chat_id],
|
||||
SET state=?
|
||||
WHERE state=?
|
||||
AND hidden=0
|
||||
AND chat_id=?;",
|
||||
paramsv![MessageState::InNoticed, MessageState::InFresh, chat_id],
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user