Reduce SQL queries

For about 1k records of git trees, gittree list page executes
more than 8k sql queries to get related fields such as domain,
subdomain, maintainers, reviewers. This patch reduces them to
3 queries, which makes page rendering cost from 15s to 3s.

For package list page, problem is the same. Reduce 3k queries
to 1 and page rendering cost from 5s to 500ms.

In simple terms, collect_related() joins more tables to include
fields into current query to avoid further hits to database.
prefetch_related() performs other separate sql queries and "join"
them in python.

Add django-debug-toolbar in development env to show debug info
such as sql queries. This plugin will be auto disabled when DEBUG
is set to False.

Fixes: #1915
Change-Id: I3bba0c765cb95a8fe267cec33847d7a3c81bdf83
Signed-off-by: Huang Hao <hao.h.huang@intel.com>
Reduce sql queires in image list page

From 23 to 1.

Change-Id: I800509d1f0895b4f6736221546839366fba21241
Reduce sql queries for domain list page.

Reduce from 98 queries to 4.

Change-Id: Ib2fdb3b37225b02e20b2746266e985eb52ea57f9
Sort domain and subdomain columns by name.

By default sort these two columns by their names.

Fixes: #1936
Change-Id: I4854692313f8851a62b35fbc4003a4dace2d8c0d