mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Merge pull request #917 from hgiesel/querynozero3
Coerce added/edited:0 to 1, Constrain rated:n to 1-365
This commit is contained in:
commit
401d5dd9cc
3 changed files with 27 additions and 7 deletions
|
@ -193,6 +193,7 @@ def test_findCards():
|
|||
assert len(col.findCards("-prop:ease>2")) > 1
|
||||
# recently failed
|
||||
if not isNearCutoff():
|
||||
# rated
|
||||
assert len(col.findCards("rated:1:1")) == 0
|
||||
assert len(col.findCards("rated:1:2")) == 0
|
||||
c = col.sched.getCard()
|
||||
|
@ -204,13 +205,14 @@ def test_findCards():
|
|||
assert len(col.findCards("rated:1:1")) == 1
|
||||
assert len(col.findCards("rated:1:2")) == 1
|
||||
assert len(col.findCards("rated:1")) == 2
|
||||
assert len(col.findCards("rated:0:2")) == 0
|
||||
assert len(col.findCards("rated:2:2")) == 1
|
||||
assert len(col.findCards("rated:0")) == len(col.findCards("rated:1"))
|
||||
|
||||
# added
|
||||
assert len(col.findCards("added:0")) == 0
|
||||
col.db.execute("update cards set id = id - 86400*1000 where id = ?", id)
|
||||
assert len(col.findCards("added:1")) == col.cardCount() - 1
|
||||
assert len(col.findCards("added:2")) == col.cardCount()
|
||||
assert len(col.findCards("added:0")) == len(col.findCards("added:1"))
|
||||
else:
|
||||
print("some find tests disabled near cutoff")
|
||||
# empty field
|
||||
|
|
|
@ -273,8 +273,8 @@ fn search_node_for_text_with_argument<'a>(
|
|||
val: &'a str,
|
||||
) -> ParseResult<SearchNode<'a>> {
|
||||
Ok(match key.to_ascii_lowercase().as_str() {
|
||||
"added" => SearchNode::AddedInDays(val.parse()?),
|
||||
"edited" => SearchNode::EditedInDays(val.parse()?),
|
||||
"added" => parse_added(val)?,
|
||||
"edited" => parse_edited(val)?,
|
||||
"deck" => SearchNode::Deck(unescape(val)?),
|
||||
"note" => SearchNode::NoteType(unescape(val)?),
|
||||
"tag" => SearchNode::Tag(unescape(val)?),
|
||||
|
@ -309,6 +309,20 @@ fn check_id_list(s: &str) -> ParseResult<&str> {
|
|||
}
|
||||
}
|
||||
|
||||
/// eg added:1
|
||||
fn parse_added(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||
let n: u32 = s.parse()?;
|
||||
let days = n.max(1);
|
||||
Ok(SearchNode::AddedInDays(days))
|
||||
}
|
||||
|
||||
/// eg edited:1
|
||||
fn parse_edited(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||
let n: u32 = s.parse()?;
|
||||
let days = n.max(1);
|
||||
Ok(SearchNode::EditedInDays(days))
|
||||
}
|
||||
|
||||
/// eg is:due
|
||||
fn parse_state(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||
use StateKind::*;
|
||||
|
@ -339,7 +353,10 @@ fn parse_flag(s: &str) -> ParseResult<SearchNode<'static>> {
|
|||
/// second arg must be between 0-4
|
||||
fn parse_rated(val: &str) -> ParseResult<SearchNode<'static>> {
|
||||
let mut it = val.splitn(2, ':');
|
||||
let days = it.next().unwrap().parse()?;
|
||||
|
||||
let n: u32 = it.next().unwrap().parse()?;
|
||||
let days = n.max(1).min(365);
|
||||
|
||||
let ease = match it.next() {
|
||||
Some(v) => {
|
||||
let n: u8 = v.parse()?;
|
||||
|
|
|
@ -216,8 +216,7 @@ impl SqlWriter<'_> {
|
|||
|
||||
fn write_rated(&mut self, days: u32, ease: Option<u8>) -> Result<()> {
|
||||
let today_cutoff = self.col.timing_today()?.next_day_at;
|
||||
let days = days.min(365) as i64;
|
||||
let target_cutoff_ms = (today_cutoff - 86_400 * days) * 1_000;
|
||||
let target_cutoff_ms = (today_cutoff - 86_400 * i64::from(days)) * 1_000;
|
||||
write!(
|
||||
self.sql,
|
||||
"c.id in (select cid from revlog where id>{}",
|
||||
|
@ -638,6 +637,7 @@ mod test {
|
|||
s(ctx, "added:3").0,
|
||||
format!("(c.id > {})", (timing.next_day_at - (86_400 * 3)) * 1_000)
|
||||
);
|
||||
assert_eq!(s(ctx, "added:0").0, s(ctx, "added:1").0,);
|
||||
|
||||
// deck
|
||||
assert_eq!(
|
||||
|
@ -728,6 +728,7 @@ mod test {
|
|||
(timing.next_day_at - (86_400 * 365)) * 1_000
|
||||
)
|
||||
);
|
||||
assert_eq!(s(ctx, "rated:0").0, s(ctx, "rated:1").0);
|
||||
|
||||
// props
|
||||
assert_eq!(s(ctx, "prop:lapses=3").0, "(lapses = 3)".to_string());
|
||||
|
|
Loading…
Reference in a new issue