Fix negated introduced:x search (#2306)

1. Add outer brackets.
2. Coalesce aggregate, because `null and true` is `null` in SQL land,
so cards that were not introduced, but manually rescheduled in the
period of interest, would not show up in a negated search.
This commit is contained in:
RumovZ 2023-01-09 23:49:35 +01:00 committed by GitHub
parent 91d563278f
commit 6df7be90c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -578,11 +578,11 @@ impl SqlWriter<'_> {
write!( write!(
self.sql, self.sql,
concat!( concat!(
"(SELECT min(id) > {cutoff} FROM revlog WHERE cid = c.id ", "((SELECT coalesce(min(id) > {cutoff}, false) FROM revlog WHERE cid = c.id ",
// Exclude manual reschedulings // Exclude manual reschedulings
"AND ease != 0) ", "AND ease != 0) ",
// Logically redundant, speeds up query // Logically redundant, speeds up query
"AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff})" "AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff}))"
), ),
cutoff = cutoff, cutoff = cutoff,
) )
@ -785,8 +785,8 @@ mod test {
s(ctx, "introduced:3").0, s(ctx, "introduced:3").0,
format!( format!(
concat!( concat!(
"((SELECT min(id) > {cutoff} FROM revlog WHERE cid = c.id AND ease != 0) ", "(((SELECT coalesce(min(id) > {cutoff}, false) FROM revlog WHERE cid = c.id AND ease != 0) ",
"AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff}))" "AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff})))"
), ),
cutoff = (timing.next_day_at.0 - (86_400 * 3)) * 1_000, cutoff = (timing.next_day_at.0 - (86_400 * 3)) * 1_000,
) )