Fix deprecation warning for DB query and fix task counting