Reduce the number of database queries by fetching all elements of the
same type at once.