Drastically reduce SQL queries fired in schedule

With SQlite and 500 jobs, this reduces the scheduler's runtime from >20s to <1s on my machine.