Change query for jobs list for more performance

The big group by clause at the end of query turned out to be a major
performance problem on postgresql.
This version gets the task counts for all jobs in four temporary tables
first, the left-outer-joins those tables.
Fix sorting by task counts
Track failures separately from attempts

This makes tasklogs of tasks that have been restarted a lot easier to
handle and is also a good first step towards treating user-initiated
interruptions of work differently from actual failures.
Change jobs tests to accomodate Task.failure col
Merge pull request #228 from guidow/optimize_jobs_list

Optimize jobs list
Change identity test to value test
Merge pull request #230 from guidow/failure_count

Track failures separately from attempts