Fix deprecation warning for DB query and fix task counting

Fixed query causing deprecation warning and also fixed the counting as it was counting files that didn't exist and therefore not versioned.