mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 05:16:39 +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> {
|
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
|
if !context
|
||||||
.sql
|
.sql
|
||||||
.exists(
|
.exists(
|
||||||
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
|
"SELECT id FROM msgs WHERE state=? AND hidden=0 AND chat_id=?;",
|
||||||
paramsv![chat_id, MessageState::InFresh],
|
paramsv![MessageState::InFresh, chat_id],
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
@@ -1760,10 +1761,11 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(),
|
|||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE msgs
|
"UPDATE msgs
|
||||||
SET state=13
|
SET state=?
|
||||||
WHERE chat_id=?
|
WHERE state=?
|
||||||
AND state=10;",
|
AND hidden=0
|
||||||
paramsv![chat_id],
|
AND chat_id=?;",
|
||||||
|
paramsv![MessageState::InNoticed, MessageState::InFresh, chat_id],
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1360,7 +1360,7 @@ CREATE INDEX devmsglabels_index1 ON devmsglabels (label);
|
|||||||
}
|
}
|
||||||
if dbversion < 68 {
|
if dbversion < 68 {
|
||||||
info!(context, "[migration] v68");
|
info!(context, "[migration] v68");
|
||||||
// the index is used to speed up get_fresh_msg_cnt(), see comment there for more details
|
// the index is used to speed up get_fresh_msg_cnt() (see comment there for more details) and marknoticed_chat()
|
||||||
sql.execute(
|
sql.execute(
|
||||||
"CREATE INDEX IF NOT EXISTS msgs_index7 ON msgs (state, hidden, chat_id);",
|
"CREATE INDEX IF NOT EXISTS msgs_index7 ON msgs (state, hidden, chat_id);",
|
||||||
paramsv![],
|
paramsv![],
|
||||||
|
|||||||
Reference in New Issue
Block a user