Optimize jobs list

Yesterday, the jobs list in our test installation developed some massive performance problems pretty much out of the blue. When the tasks table was busy (because a job was running and task states were being changed), the runtime for the job list query would rise continuously, going up to ~20 minutes in the worst case. (No, really. 20 minutes). According to postgres' "EXPLAIN ANALYZE" function, the final big GROUP BY step would take 5 Gigabytes of memory to complete in those cases.

Changing the query to do the task counts inside the four subqueries allowed me to get rid of the big group by clause. The runtime for this query dropped to ~1.5 milliseconds in all cases as a result.