refactor code to fetch tasks.size with one line sql