Reduce SQL queries

Reduced the number of SQL queries about 50% in ``Licence`` and ``Hardware`` list view.

@quamilek @xliiv please review.