Add sql condition for speedup in write_introduced

This commit is contained in:
RumovZ 2021-04-19 08:19:19 +02:00
parent 3cecc7157b
commit 11cd1d9a26

View file

@ -500,8 +500,11 @@ impl SqlWriter<'_> {
let cutoff = self.cutoff_in_secs_from_days(days)? * 1_000; let cutoff = self.cutoff_in_secs_from_days(days)? * 1_000;
write!( write!(
self.sql, self.sql,
concat!(
"(select min(id) > {} from revlog where cid = c.id)", "(select min(id) > {} from revlog where cid = c.id)",
cutoff "and c.id in (select cid from revlog where id > {})"
),
cutoff, cutoff,
) )
.unwrap(); .unwrap();
Ok(()) Ok(())
@ -671,8 +674,11 @@ mod test {
assert_eq!( assert_eq!(
s(ctx, "introduced:3").0, s(ctx, "introduced:3").0,
format!( format!(
"((select min(id) > {} from revlog where cid = c.id))", concat!(
(timing.next_day_at.0 - (86_400 * 3)) * 1_000 "((select min(id) > {cutoff} from revlog where cid = c.id)",
"and c.id in (select cid from revlog where id > {cutoff}))"
),
cutoff = (timing.next_day_at.0 - (86_400 * 3)) * 1_000,
) )
); );
assert_eq!(s(ctx, "introduced:0").0, s(ctx, "introduced:1").0,); assert_eq!(s(ctx, "introduced:0").0, s(ctx, "introduced:1").0,);