Some db-query speedups