fix error when gathering new cards in reverse position

Also simplify order clause - with did and queue limited to a constant,
SQLite is smart enough to use the covering index for sorting by due.
This commit is contained in:
Damien Elmes 2021-12-06 17:05:55 +10:00
parent fcb21ceed5
commit d515939340
2 changed files with 3 additions and 6 deletions

View file

@ -241,9 +241,9 @@ impl super::SqliteStorage {
F: FnMut(NewCard) -> bool, F: FnMut(NewCard) -> bool,
{ {
let mut stmt = self.db.prepare_cached(&format!( let mut stmt = self.db.prepare_cached(&format!(
"{}{}", "{} ORDER BY {}",
include_str!("new_cards.sql"), include_str!("new_cards.sql"),
if reverse { " order by due desc" } else { "" } if reverse { "due desc" } else { "due asc" }
))?; ))?;
let mut rows = stmt.query(params![deck])?; let mut rows = stmt.query(params![deck])?;
while let Some(row) = rows.next()? { while let Some(row) = rows.next()? {

View file

@ -7,6 +7,3 @@ SELECT id,
FROM cards FROM cards
WHERE did = ? WHERE did = ?
AND queue = 0 AND queue = 0
ORDER BY did,
queue,
due