simplify the sql query

This commit is contained in:
Simon Laux
2023-01-07 02:24:09 +01:00
parent 0eb67cff7e
commit ae412b628b

View File

@@ -369,29 +369,22 @@ pub async fn get_chatlistitem_for_chat(
) -> Result<(ChatId, Option<MsgId>)> { ) -> Result<(ChatId, Option<MsgId>)> {
// Similar result as normal chatlist, only one item though and: // Similar result as normal chatlist, only one item though and:
// archived and blocked chats are included // archived and blocked chats are included
context let msg_id = context
.sql .sql
.query_row( .query_row(
"SELECT c.id, m.id "SELECT id
FROM chats c
LEFT JOIN msgs m
ON c.id=m.chat_id
AND m.id=(
SELECT id
FROM msgs FROM msgs
WHERE chat_id=c.id WHERE chat_id=?2
AND (hidden=0 OR state=?1) AND (hidden=0 OR state=?1)
ORDER BY timestamp DESC, id DESC LIMIT 1) ORDER BY timestamp DESC, id DESC LIMIT 1",
WHERE c.id=?2
GROUP BY c.id",
paramsv![MessageState::OutDraft, chat_id], paramsv![MessageState::OutDraft, chat_id],
|row: &rusqlite::Row| { |row: &rusqlite::Row| {
let chat_id: ChatId = row.get(0)?; let msg_id: Option<MsgId> = row.get(0)?;
let msg_id: Option<MsgId> = row.get(1)?; Ok(msg_id)
Ok((chat_id, msg_id))
}, },
) )
.await .await?;
Ok((chat_id, msg_id))
} }
#[cfg(test)] #[cfg(test)]