mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
fix: initialise last_msg_id to the highest known row id
Otherwise existing bots migrating to get_next_msgs() are trying to process all the messages they have in the database.
This commit is contained in:
@@ -814,7 +814,22 @@ impl Context {
|
|||||||
pub async fn get_next_msgs(&self) -> Result<Vec<MsgId>> {
|
pub async fn get_next_msgs(&self) -> Result<Vec<MsgId>> {
|
||||||
let last_msg_id = match self.get_config(Config::LastMsgId).await? {
|
let last_msg_id = match self.get_config(Config::LastMsgId).await? {
|
||||||
Some(s) => MsgId::new(s.parse()?),
|
Some(s) => MsgId::new(s.parse()?),
|
||||||
None => MsgId::new_unset(),
|
None => {
|
||||||
|
// If `last_msg_id` is not set yet,
|
||||||
|
// subtract 1 from the last id,
|
||||||
|
// so a single message is returned and can
|
||||||
|
// be marked as seen.
|
||||||
|
self.sql
|
||||||
|
.query_row(
|
||||||
|
"SELECT IFNULL((SELECT MAX(id) - 1 FROM msgs), 0)",
|
||||||
|
(),
|
||||||
|
|row| {
|
||||||
|
let msg_id: MsgId = row.get(0)?;
|
||||||
|
Ok(msg_id)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = self
|
let list = self
|
||||||
|
|||||||
Reference in New Issue
Block a user