Improve performance of applications index.

Some tweaks to avoid unnecessary db queries when building the index.
This reduces the number of queries per index row from c. 20 to 4.  Most
of the 20 queries hit the query cache, but that still slows things down.
On my dev VM, this improved the rendering time from c. 1550 ms to c.
600ms
Merge pull request #49 from alphagov/index_speedup

Improve performance of applications index.