threads = Thread.objects.annotate(Count('comments', distinct=True)).annotate(
    Count('upvotes', distinct=True))
for thread in threads:
    print(thread.comments__count)
print(thread.upvotes__count)
prefetch_related Django только для подсчета