Fix performance issue: use queryset.count()